OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

A unified distributed database ready for your transactional, analytical, and AI workloads.

DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Database

SQL - V4.1.0

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive DemosTraining & Certification
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Database
    3. SQL
    4. V4.1.0
    iconOceanBase Database
    SQL - V 4.1.0
    SQL
    KV
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    CREATE SYNONYM

    Last Updated:2023-07-28 02:55:43  Updated
    share
    What is on this page
    Purpose
    Syntax
    Parameters
    Examples
    Considerations

    folded

    share

    Purpose

    You can use this statement to create a synonym.

    Syntax

    CREATE [ OR REPLACE ] [ PUBLIC ] SYNONYM [ synonym_schema. ]synonym_name
    FOR [ object_schema. ]object_name;
    

    Parameters

    Parameter Description
    OR REPLACE Specifies to use a new definition to recreate the view if the name of the view to be created already exists.
    PUBLIC Specifies to create a public synonym, which can be used by allusers. Only users with the corresponding privileges on the underlying object can use this synonym. A public synonym is used in parsing the reference to an object only when no schema is specified for the object. If PUBLIC is not specified, the synonym is private and accessible only within its schema. The name of a private synonym must be unique in its schema.
    synonym_schema The schema where the synonym is located. If schema. is omitted, the synonym is in your own schema by default. If PUBLIC is specified, schema cannot be specified for the synonym.
    synonym_name The name of the synonym.
    object_schema The schema that contains the object for which the synonym is created. If schema. is omitted, the object for which the synonym is created is in your own schema by default.
    object_name The name of the object for which the synonym is created.

    Examples

    • Create a synonym for a table.

      obclient> CREATE TABLE tbl1(col1 INT,col2 INT);
      Query OK, 0 rows affected
      
      obclient> CREATE SYNONYM syn1 FOR tbl1;
      Query OK, 0 rows affected
      
      obclient> INSERT INTO syn1 values(1,1);
      Query OK, 1 row affected
      
      obclient> SELECT * FROM syn1;
      +------+------+
      | COL1 | COL2 |
      +------+------+
      |    1 |    1 |
      +------+------+
      1 row in set
      
    • Create a public synonym.

      obclient> CREATE PUBLIC SYNONYM syn2 FOR tbl1;
      Query OK, 0 rows affected
      

    Considerations

    The following part describes the privileges required for creating different types of synonyms:

    • To create a private synonym in your own schema, you must have the CREATE SYNONYM privilege.

    • To create a private synonym in another user's schema, you must have the CREATE ANY SYNONYM privilege.

    • To create a public synonym, you must have the CREATE PUBLIC SYNONYM privilege.

    • The object for which the synonym is created does not need to exist and you do not need to have privileges to access the object.

    /* Create a user named synonym_user.*/
    obclient> CREATE USER synonym_user IDENTIFIED BY synonym_user;
    Query OK, 0 rows affected
    
    obclient> GRANT CREATE ON *.* TO synonym_user;
    Query OK, 0 rows affected
    
    obclient> GRANT SELECT ON *.* TO synonym_user;
    Query OK, 0 rows affected
    
    /*Connect to user synonym_user.*/
    obclient> CREATE OR REPLACE SYNONYM syn1 FOR tbl1;
    ERROR-00600: internal error code, arguments: -5036, Access denied; you need (at least one of) the CREATE SYNONYM privilege(s) for this operation
    
    /*Grant the CREATE SYNONYM privilege to user synonym_user.*/
    obclient> GRANT CREATE SYNONYM TO synonym_user;
    Query OK, 0 rows affected
    
    obclient> CREATE OR REPLACE SYNONYM syn1 FOR tbl1;
    Query OK, 0 rows affected
    

    Previous topic

    CREATE SEQUENCE
    Last

    Next topic

    CREATE TABLE
    Next
    What is on this page
    Purpose
    Syntax
    Parameters
    Examples
    Considerations