本文转自:http://blog.csdn.net/generalfu/article/details/7906561
同义词定义 当一个用户想访问另外一个用户的表时, 需要在表前加用户名,总加表名不方便, 为此可以为用户名、表名起个小名别名, 以方便访问,此别名就是同义词。
创建同义词 create synonym 同义词名 for 用户名.表名称;
删除同义词 drop synonym syn_name;
测试实例 --没有创建同义词之前
- SQL> select * from scott.emp where deptno = 10;
- EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
- ----- ---------- --------- ----- ----------- --------- --------- ------
- 7782 CLARK MANAGER 7839 1981-6-9 2450.00 10
- 7839 KING PRESIDENT 1981-11-17 5000.00 10
- 7934 MILLER CLERK 7782 1982-1-23 1300.00 10
- Executed in 0.078 seconds
SQL> select * from scott.emp where deptno = 10; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
----- ---------- --------- ----- ----------- --------- --------- ------
7782 CLARK MANAGER 7839 1981-6-9 2450.00 10
7839 KING PRESIDENT 1981-11-17 5000.00 10
7934 MILLER CLERK 7782 1982-1-23 1300.00 10 Executed in 0.078 seconds
--创建同义词
- SQL> create synonym myemp for scott.emp;
- Synonym created
- Executed in 0.265 seconds
SQL> create synonym myemp for scott.emp; Synonym created Executed in 0.265 seconds
--使用同义词
- SQL> select * from myemp where deptno = 10;
- EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
- ----- ---------- --------- ----- ----------- --------- --------- ------
- 7782 CLARK MANAGER 7839 1981-6-9 2450.00 10
- 7839 KING PRESIDENT 1981-11-17 5000.00 10
- 7934 MILLER CLERK 7782 1982-1-23 1300.00 10
- Executed in 0.047 seconds