[DB2] Add SYNONYM to the DB TABLE [SYNONYM]

What is SYNONYM

SYNONYM is give a table name an other name so that you can access the data with that other name.

For example, if there is a table name: A, another name: B is added.

In that case, you can refer to A with 「SELECT * FROM B」.

How to SYNONYM creation

①Grant SYNONYM

Create a SYNONYM added by table name: A, another name: B

CREATE PUBLIC SYNONYM B FOR A

You can prevent it from being used by other users by removing “PUBLIC”.

CREATE SYNONYM B FOR A

②Change SYNONYM

After granting SYNONYM, you can change it.

RENAME B TO C

③Delete SYNONYM

How to remove SYNONYM when it is no longer needed.

DROP PUBLIC SYNONYM B

④Confirmation of SYNONYM

Check which DB TABLE has SYNONYM

SELECT TABNAME, BASE_TABNAME FRON SYSCAT.TABLE

TABNAME: another name (SYNONYM)
BASE_TABNAME:DB TABLE name (True TABLE name)

Follow me!

コメントする

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です