CREATE SYNONYM Statements

  • Capella Columnar
  • reference
    +
    This topic describes how you can use CREATE statements to create synonyms for your Capella Columnar collections.

    Syntax

    CreateSynonym EBNF
    CreateSynonym ::= "CREATE" "ANALYTICS"? "SYNONYM" QualifiedName ("IF" "NOT" "EXISTS")? "FOR" QualifiedName
    CreateSynonym Diagram
    "CREATE" "SYNONYM" QualifiedName ("IF" "NOT" "EXISTS")? "FOR" QualifiedName

    The first QualifiedName is the full name of the synonym.

    Examples

    This example sets h to be a synonym in the scope travel-sample.inventory for the collection hotel.

      CREATE SYNONYM `travel-sample`.inventory.h FOR `travel-sample`.inventory.hotel;
    Show additional examples

    This example creates a database, scope, and collection, and then creates a synonym with a shorter name for the collection.

      CREATE DATABASE db1;
      CREATE SCOPE db1.scope1;
      CREATE COLLECTION db1.scope1.a_very_very_very_long_collection_name PRIMARY KEY (id:int);
      CREATE SYNONYM db1.scope1.coll1 FOR db1.scope1.a_very_very_very_long_collection_name;
    
      USE db1.scope1;
      SELECT COUNT(*) FROM coll1;

    The next example creates a reference to an object that belongs to a different database or scope so that you do not have to fully qualify it.

      CREATE database db1;
      CREATE scope db1.scope1;
      CREATE collection db1.scope1.coll1 PRIMARY KEY (id:int);
    
      CREATE database db2;
      CREATE scope db2.scope2;
      CREATE synonym db2.scope2.coll1_from_db1 FOR db1.scope1.coll1;

    To access db1.scope1.col1 from the context of db2.scope2:

      USE db2.scope2;
      SELECT COUNT(*) FROM coll1_from_db1;

    Arguments

    FOR

    The FOR clause specifies the target of the synonym. The QualifiedName in this clause is the fully qualified name of a collection.

    For information about how Capella Columnar organizes entities into a database.scope.database_object hierarchy and resolves names, see Entities in Capella Columnar Services.