Description
Create synonyms. A synonym is a database object, similar to giving an object an alias. It supports creating synonyms for the following objects: table, table stream, dynamic table, materialized view, volume, function.
Syntax
-
TABLE|VOLUME|FUNCTION: Indicates the type of object for which the synonym is being created,
- TABLE: This is the default option. Used to create synonyms for tables, table streams, materialized views, and dynamic tables. In these cases, the "table" keyword is optional.
- VOLUME: When creating a synonym for a volume, this keyword must be explicitly specified. If omitted, the system will default to looking for a table object with the same name.
- FUNCTION: When creating a synonym for a function, this keyword is mandatory. If not specified, the system will also default to looking for a table object with the same name.
-
synonym_name: The name of the synonym, following metadata conventions.
-
object: Specifies the name of the base object. Supports formats like workspace_name.schema_name_2.object_name and schema_name_2.name. If the schema is omitted, the object in the current schema will be used.
Permissions
- Creating a synonym requires create synonym permission.
Usage
- For specific usage, refer to Synonym Usage
- When a synonym reference (such as TABLE, TABLE STREAM, MATERIALIZED VIEW, DYNAMIC TABLE, VOLUME, FUNCTION, etc.) is deleted, and a new reference with the same name is subsequently created, the system will automatically point to and use the new reference. This means that any reference to the original object will automatically apply to the new object after it is created, without the need to change existing queries or code.
Example
Case 1: Creating a synonym for a table
Case 2: Create a synonym for table stream, the syntax for creating a synonym for table stream is the same as for table
Case 3: Create a synonym for DYNAMIC TABLE, the syntax for creating a synonym for DYNAMIC TABLE is the same as for TABLE