You can use the DROP SYNONYM statement to drop a synonym. This topic describes how to drop a synonym.
Prerequisites
To drop a private synonym, you must be the owner of this private synonym, or have the
DROP ANY SYNONYMsystem privilege.To drop a public synonym, you must have the
DROP PUBLIC SYNONYMsystem privilege.
Syntax
DROP [PUBLIC] SYNONYM [ schema. ]synonym;
Parameters
| Parameter | Description |
|---|---|
| PUBLIC | You can specify PUBLIC to drop a public synonym. If you do not specify PUBLIC, a private synonym is dropped. |
| [ schema. ]synonym | Specifies the schema to which the synonym to be created belongs. If you have specified PUBLIC, you cannot specify the schema for the synonym. The synonym field specifies the name of the synonym. |
Examples
Example 1
Drop a private synonym.
View the
spsynonym.obclient> SELECT * FROM USER_SYNONYMS WHERE SYNONYM_NAME = 'SP'; +--------------+-------------+------------+---------+---------------+ | SYNONYM_NAME | TABLE_OWNER | TABLE_NAME | DB_LINK | ORIGIN_CON_ID | +--------------+-------------+------------+---------+---------------+ | SP | SYS | DWS_NY | NULL | 0 | +--------------+-------------+------------+---------+---------------+ 1 row in setDrop the
spsynonym.obclient> DROP SYNONYM sp; Query OK, 0 rows affectedView the sp synonym again.
obclient> SELECT * FROM USER_SYNONYMS WHERE SYNONYM_NAME = 'SP'; Empty set
Example 2
Drop a public synonym.
View the
spbsynonym.obclient> SELECT * FROM ALL_SYNONYMS WHERE SYNONYM_NAME = 'SPB'; +--------+--------------+-------------+------------+---------+ | OWNER | SYNONYM_NAME | TABLE_OWNER | TABLE_NAME | DB_LINK | +--------+--------------+-------------+------------+---------+ | PUBLIC | SPB | SYS | DWS_NY1 | NULL | +--------+--------------+-------------+------------+---------+ 1 row in setDrop the
spbsynonym.obclient> DROP PUBLIC SYNONYM spb; Query OK, 0 rows affectedView the
spbsynonym again.obclient> SELECT * FROM ALL_SYNONYMS WHERE SYNONYM_NAME = 'SPB'; Empty set