标签:upd from 名称 主键 设置 _id nts 标签 sql语句
创建一个名称为EMPLOYEES_VU的视图,它基于EMPLOYEES表中的雇员号、雇员名和部门号。将雇员名的列标题改为EMPLOYEE。
CREATE VIEW EMPLOYEES_VU AS SELECT EMPLOYEE_ID EMPLOYEE,FIRST_NAME,LAST_NAME,DEPARTMENT_ID FROM EMPLOYEES;
从USER_VIEWS数据字典视图中选择视图名字和文本
SELECT * FROM USER_VIEWS;
使用EMPLOYEES_VU视图,输入一个查询来显示所有的雇员名和部门号
SELECT FIRST_NAME,LAST_NAME,DEPARTMENT_ID FROM EMPLOYEES_VU;
创建一个名为DEPT50视图,其中包含部门50中的所有雇员的雇员号、雇员名和部门号,视图的列标签为EMPNO、EMPLOYEE和DEPTNO,不允许通过视图将一个雇员重新分配到另一个部门
CREATE OR REPLACE VIEW DEPT50(EMPNO,EMPLOYEE,DEPTNO) AS SELECT EMPLOYEE_ID,LAST_NAME,DEPARTMENT_ID FROM EMPLOYEES WHERE DEPARTMENT_ID=50 WITH CHECK OPTION;
视图重新指定Matos到部门80
UPDATE DEPT50 SET DEPTNO=80 WHERE EMPLOYEE=‘Matos‘;
ORA-01402: 视图 WITH CHECK OPTION where 子句违规
创建一个名为SALARY_VU的视图,该视图基于所有雇员的名字、部门号、薪水和薪水级别。用EMPLOYEES、DEPARTMENTS和JOB_GRADES表,分别命名列标签为Employy、Department、Salary和Grade。
GRANT SELECT ON SALGRADE TO HR;
CREATE TABLE SAL_LEVEL AS SELECT * FROM SCOTT.SALGRADE;
CREATE OR REPLACE VIEW SALARY_VU(Employee,Department,Salary,Grade)
AS
SELECT EMPLOYEES.LAST_NAME,DEPARTMENTS.DEPARTMENT_NAME,EMPLOYEES.SALARY,SAL_LEVEL.GRADE
FROM EMPLOYEES,DEPARTMENTS,SAL_LEVEL
WHERE EMPLOYEES.DEPARTMENT_ID=DEPARTMENTS.DEPARTMENT_ID AND (EMPLOYEES.SALARY BETWEEN SAL_LEVEL.LOSAL AND SAL_LEVEL.HISAL);
创建一个表DEPT_2复制到DEPT内容,并在创建表之后给department_id设置主键。
CREATE TABLE DEPT_2 AS SELECT * FROM DEPT;
ALTER TABLE DEPT_2 ADD CONSTRAINT PK_1 PRIMARY KEY(DEPTNO);
标签:upd from 名称 主键 设置 _id nts 标签 sql语句
原文地址:https://www.cnblogs.com/kawashibara/p/8962415.html