The CREATE ALIAS statement defines an alias for a table, view, or another alias.
Invocation
This statement can be embedded in an application program or issued through the use of dynamic SQL statements. It is an executable statement that can be dynamically prepared.
Authorization
The privileges held by the authorization ID of the statement must include as least one of the following:
To use the referenced object via the alias, the same privileges are required on that object as would be necessary if the object itself were used.
Syntax
>>-CREATE----+-ALIAS--------+--alias-name---FOR-----------------> | (1) | '-SYNONYM------' >-----+-table-name--+------------------------------------------>< +-view-name---+ '-alias-name2-'
Notes:
|
Description
If a two-part name is specified, the schema name cannot begin with "SYS" (SQLSTATE 42939).
The rules for defining an alias name are the same as those used for defining a table name.
Notes
Examples
Example 1: HEDGES attempts to create an alias for a table T1 (both unqualified).
CREATE ALIAS A1 FOR T1
The alias HEDGES.A1 is created for HEDGES.T1.
Example 2: HEDGES attempts to create an alias for a table (both qualified).
CREATE ALIAS HEDGES.A1 FOR MCKNIGHT.T1
The alias HEDGES.A1 is created for MCKNIGHT.T1.
Example 3: HEDGES attempts to create an alias for a table (alias in a different schema; HEDGES is not a DBADM; HEDGES does not have CREATEIN on schema MCKNIGHT).
CREATE ALIAS MCKNIGHT.A1 FOR MCKNIGHT.T1
This example fails (SQLSTATE 42501).
Example 4: HEDGES attempts to create an alias for an undefined table (both qualified; FUZZY.WUZZY does not exist).
CREATE ALIAS HEDGES.A1 FOR FUZZY.WUZZY
This statement succeeds but with a warning (SQLSTATE 01522).
Example 5: HEDGES attempts to create an alias for an alias (both qualified).
CREATE ALIAS HEDGES.A1 FOR MCKNIGHT.T1 CREATE ALIAS HEDGES.A2 FOR HEDGES.A1
The first statement succeeds (as per example 2).
The second statement succeeds and an alias chain is created, consisting of HEDGES.A2 which refers to HEDGES.A1 which refers to MCKNIGHT.T1. Note that it does not matter whether or not HEDGES has any privileges on MCKNIGHT.T1. The alias is created regardless of the table privileges.