数据库

数据库同义词

2020-03-14  本文已影响0人  风中小酌

可以除去对象名必须带的方案限制,并提供一个可替换的对象名,对具有特别长的对象的名字特别有用。

创建同义词

CREATE SYNONYM 同义词名 FOR 对象名;

SQL> create synonym em for employees;
Synonym created

使用同义词
SQL> select * from em where last_name='Tommy';
EMPLOYEE_ID FIRST_NAME           LAST_NAME                 EMAIL                     PHONE_NUMBER         HIRE_DATE   JOB_ID         SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
----------- -------------------- ------------------------- ------------------------- -------------------- ----------- ---------- ---------- -------------- ---------- -------------
       2500                      Tommy                     se@sfe.com                                     2007/11/1 星 IT_PROG     500078.00                           

查询同义词

同义词表 user_synonyms

SQL> select * from user_synonyms;
SYNONYM_NAME                   TABLE_OWNER                    TABLE_NAME                     DB_LINK
------------------------------ ------------------------------ ------------------------------ --------------------------------------------------------------------------------
EM                             HR                             EMPLOYEES                      

删除同义词

DROP SYNONYM 同义词名

SQL> drop synonym em;
Synonym dropped

SQL> select * from em where last_name='Tommy';
select * from em where last_name='Tommy'
ORA-00942: 表或视图不存在
上一篇下一篇

猜你喜欢

热点阅读