Exercise 6 Creating Database Objects
2026-04-09 10:31
Tags: #ADV_DBMS
Author: Duke Hsu
Question 1
The staff in the HR department wants to hide some of the data in the EMPLOYEES table. They want a view called EMPLOYEES_VU based on the employee numbers, employee names, and department numbers from the EMPLOYEES table. They want the heading for the employee’s name to be EMPLOYEE.
1 2 3 4 | |
Question 2
Confirm that the view works. Display the contents of the EMPLOYEES_VU view
1 2 | |
Question 3
Using your EMPLOYEES_VU view, write a query for the HR department to display all employee names and department numbers.
1 2 3 4 | |
Question 4
Department 50 needs access to its employee data. Create a view named DEPT50 that contains the employee numbers, employee last names, and department numbers for all employees in department 50. You have been asked to label the view columns EMPNO, EMPLOYEE, and DEPTNO. For security purposes, do not allow an employee to be reassigned to another department through the view.
Tips
For security purposes, do not allow an employee to be reassigned to another department through the view. -- We need add WITH CHECK OPTION
1 2 3 4 5 6 | |
Question 5
Test your view. Attempt to reassign Matos to department 80.
1 2 3 4 | |
Error messages:
1 2 3 4 5 6 7 8 | |
Question 6
You need a sequence that can be used with the PRIMARY KEY column of the DEPARTMENTS table. The sequence should start at 280 and have a maximum value of 1,000. Have your sequence increment by 10. Name the sequence DEPT_ID_SEQ.
1 2 3 4 5 6 7 8 | |
Question 7
To test your sequence, write a query to insert two rows in the DEPARTMENTS table. Be sure to use the sequence that you created for the ID column. Add two departments: Education and Administration.
1 2 3 4 5 6 7 8 9 10 11 | |
Question 8
Confirm insert data
1 2 | |
Question 9
Create a non-unique index on the NAME column in the DEPARTMENTS table.
Tips
In some tables, column values may be duplicated, so we use a non-unique index. By default, indexes are non-unique.
1 2 3 | |
Question 10
Tips
A synonym cannot be altered. You need to create a new synonym first before dropping the old one.
Create a synonym for your EMPLOYEES table. Call it EMP.
1 2 3 | |
Using SYNONYM
1 2 | |
References
Exercise #6