SQL administration (naming convenience): which SQL command is used to create a synonym name that points to an existing schema object for easier referencing?

Difficulty: Easy

Correct Answer: CREATE SYNONYM

Explanation:


Introduction / Context:
In some SQL implementations (notably Oracle and a few others), a synonym provides an alternate name for a table, view, sequence, procedure, or other schema object. This helps when cross-schema access would otherwise require long qualified names, or when you want to insulate applications from future object renames/moves.


Given Data / Assumptions:

  • We are discussing vendor dialects that support synonyms.
  • We want the command that creates the indirection name.
  • Focus is on DDL, not DML.


Concept / Approach:
The DDL statement is CREATE SYNONYM. After creation, the synonym can be used in SQL statements as if it were the original object, subject to privileges. CREATE SCHEMA defines a namespace and can create objects but does not create aliases. CREATE SAME is not a valid SQL statement. Therefore, the correct choice is CREATE SYNONYM.


Step-by-Step Solution:

Identify need: alternate name for an existing object.Map to DDL: CREATE SYNONYM target FOR original_object.Select “CREATE SYNONYM.”


Verification / Alternative check:
In practice, CREATE SYNONYM emp FOR hr.employees; allows referring to emp instead of hr.employees in queries (assuming privileges).


Why Other Options Are Wrong:

CREATE SCHEMA: creates a schema; not a synonym.CREATE SAME: not an SQL command.All/None: incorrect given the specific command exists.


Common Pitfalls:
Assuming all RDBMS products support synonyms; alternatives include views or search_path adjustments (PostgreSQL) where synonyms are not implemented.


Final Answer:
CREATE SYNONYM

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion