如果其定义具有唯一约束的列,是否需要在视图中指定别名?

时间:2016-03-02 06:18:56

标签: sql oracle11g sql-view

Oracle指定"you must specify aliases if the view definition includes constraints." 但是在下面的查询中,列电子邮件有一个唯一的约束,但没有别名。这样可以正常工作。为什么?

CREATE VIEW emp_sal (emp_id, last_name, 
      email UNIQUE RELY DISABLE NOVALIDATE,
   CONSTRAINT id_pk PRIMARY KEY (emp_id) RELY DISABLE NOVALIDATE)
   AS SELECT employee_id, last_name, email FROM employees;

1 个答案:

答案 0 :(得分:0)

有趣的是,视图定义中有别名:

CREATE VIEW emp_sal (emp_id, last_name, 
      email UNIQUE RELY DISABLE NOVALIDATE,
   CONSTRAINT id_pk PRIMARY KEY (emp_id) RELY DISABLE NOVALIDATE)
   AS SELECT employee_id, last_name, email FROM employees;

这里emp_id, last_name, email只是别名。