Synonyms (deprecated)
A synonym is an alternate name for a table or view. A synonym can be used to reference a table or view in cases where an existing table or view can be referenced.
Synonyms
are deprecated.
In Db2 12, packages bound with APPLCOMPAT(V12R1M504 or higher cannot issue CREATE synonym
statements. Use aliases instead.
Synonyms are similar to aliases but
are supported only for compatibility with previous releases Aliases behave the same for all
Db2 family products. For more about
aliases, see Aliases and CREATE ALIAS. Existing
synonyms remain supported, but support might be removed in the future.
Differences between synonyms and aliases
The following table summarizes the differences between aliases and synonyms, which are deprecated.
| Characteristic | Synonyms (deprecated) | Aliases |
|---|---|---|
| Requires authorization to create? | No | Yes |
| Can be defined on objects not at the current sever? | No | Yes |
| Can be defined on the name of an object that does not yet exist? | No | Yes, but the object must exist when the alias is used |
| Is dropped when referenced objects are dropped? | Yes | No |
| Uses a qualified object name for the object? | No, uses a one-part name | Yes |
| Can be referenced or used by users other than the object owner? | No | Yes |
The option of referencing a table or view by a synonym is not explicitly shown in the syntax diagrams or mentioned in the description of SQL statements. But synonyms can be referred to in an SQL statement, with one exception: a synonym cannot be used in the CREATE SYNONYM statement.
Like tables and views, a synonym can be created, dropped, and associated with a comment. No authority is necessary to use a synonym. However, access to the tables and views that are referenced by the synonym still requires the appropriate authorization for the current statement.
A synonym is created with the CREATE SYNONYM statement.
A synonym name designates a synonym when it is preceded by the keyword SYNONYM, as in CREATE SYNONYM and DROP SYNONYM. In all other contexts, a synonym designates a table or a view. In all other contexts, a synonym designates a local table or view and can be used wherever the name of a table or view can be used in an SQL statement.
The effect of using a synonym in an SQL statement is the same as text substitution. For example,
if S is a synonym for Q.T, one of the steps involved in the preparation of SELECT * FROM
S is the replacement of 'S' by 'Q.T'.
