SQL statement common view operation part test questions (1)

Create a view named EMPLOYEES_VU based on the employee number, employee name, and department number in the EMPLOYEES table. Change the EmployeeName column heading to EMPLOYEE.

CREATE VIEW EMPLOYEES_VU AS SELECT EMPLOYEE_ID EMPLOYEE,FIRST_NAME,LAST_NAME,DEPARTMENT_ID FROM EMPLOYEES;

Select view name and text from USER_VIEWS data dictionary view

SELECT * FROM USER_VIEWS;

Using the EMPLOYEES_VU view, enter a query to display all employee names and department numbers

    SELECT FIRST_NAME,LAST_NAME,DEPARTMENT_ID FROM EMPLOYEES_VU;

Create a view called DEPT50 that contains the employee number, employee name, and department number of all employees in department 50. The column labels of the view are EMPNO, EMPLOYEE, and DEPTNO. Views are not allowed to reassign one employee to another department

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;

View reassign Matos to sector 80

UPDATE DEPT50 SET DEPTNO=80 WHERE EMPLOYEE='Matos';

ORA-01402: view WITH CHECK OPTION where clause violation

Create a view called SALARY_VU based on all employees' first names, department numbers, salaries, and salary grades. Use the EMPLOYEES, DEPARTMENTS, and JOB_GRADES tables, and name the column labels Employy, Department, Salary, and Grade, respectively.

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);

Create a table DEPT_2 copied to DEPT content, and set the primary key for department_id after the table is created.

CREATE TABLE DEPT_2 AS SELECT * FROM DEPT;

ALTER TABLE DEPT_2 ADD CONSTRAINT PK_1 PRIMARY KEY(DEPTNO);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324952340&siteId=291194637