Module 3: DB2 Objects
Synonym
A synonym is an alternative, private name for a table or view. It is a personal shortcut - it can be used only by the person who creates it.
What is a synonym
- A synonym is an alternative name for a table or view.
- It is private - only the creator can use it. Other users cannot see or use your synonyms.
- When a table is dropped, its synonyms are dropped automatically, but its aliases are retained.
- Synonyms are handy in interactive SQL (SPUFI/QMF) to avoid typing long qualified names.
- Synonyms are created with CREATE SYNONYM and removed with DROP SYNONYM.
CREATE SYNONYM - example
- A short private name CUST for the CUSTOMER table:-
CREATE SYNONYM CUST FOR MM01.CUSTOMER;
- You can now code SELECT * FROM CUST; instead of SELECT * FROM MM01.CUSTOMER;
- Need to share the shortcut with others? Use CREATE ALIAS instead - synonyms stay private.
