1. Alter Dept table to add the constraint of PRIMARY KEY on Dept_No.
ALTER TABLE Dept
ADD CONSTRAINT PK_Dept PRIMARY KEY (Dept_No); 2. Create Index on Dept_Name column of Dept table. CREATE INDEX idx_Dept_Dept_Name ON Dept (Dept_Name); 3. List down the names of employees who work in ‘CS’ department [Hint: ‘CS’ is data value for Dept_Name column in Dept table]. SELECT e.name FROM employees e JOIN Dept d ON e.department_number = d.Dept_No WHERE d.Dept_Name = 'CS'; 4. Generate a sequence starting with ten (10) and ending with hundred (100) while considering the increment of two (2). Make use of sequence on the Emp_No column of Employee table. -- Create a sequence CREATE SEQUENCE emp_no_sequence START WITH 10 INCREMENT BY 2 MINVALUE 10 MAXVALUE 100 CYCLE;
-- Update the Emp_No column in the Employee table
UPDATE Employee SET Emp_No = nextval('emp_no_sequence'); 5. Remove a Sequence from the Data Dictionary. DROP SEQUENCE sequence_name; 6. Describe the structure of Employee table. DESCRIBE Employee; 7. Add a column named ‘Commission’ with a data type varchar2 in the Employee table. ALTER TABLE Employee ADD Commission VARCHAR2(50); 8. Create ‘Dept table’ having columns of (Dept_No, Dept_Name, and Dept_Loc) and apply UNIQUE constraint on Dept_Name column. CREATE TABLE Dept ( Dept_No INT, Dept_Name VARCHAR(50), Dept_Loc VARCHAR(50), CONSTRAINT UC_Dept_Name UNIQUE (Dept_Name) ); 9. To display the names of employees whose name starts with ‘s’. The remaining characters of the employee name can be anything. SELECT name FROM employees WHERE name LIKE 's%'; 10. To display the names of employees whose name has an ‘a’ as the second character while the first character can be anything. In addition, there can be many characters after the second character which is ‘a’. SELECT name FROM employees WHERE name LIKE '_a%'; 11. To select the employees who has a job title of ‘CLERK’ and earns more than 1100 [Hint: CLERK is a data value in Emp_Job column]. SELECT * FROM employees WHERE Emp_Job = 'CLERK' AND Emp_Salary > 1100; 12. Remove an index from Data Dictionary. DROP INDEX index_name; 13. Add a Eligible constraint on Dept_Loc in Dept table ALTER TABLE Dept ADD CONSTRAINT CK_Dept_Eligible CHECK (Dept_Loc IN ('Location1', 'Location2', 'Location3')); 14. Update any record from Dept table. UPDATE Dept SET Dept_Name = 'New Department Name', Dept_Loc = 'New Department Location' WHERE Dept_No = 123; 15. Display a current of sequence from Emp table. SELECT currval('emp_emp_no_seq'); 16. Create a view of Emp table by using (Emp_ID, Emp_Name, Emp_Salary). CREATE VIEW EmpView AS SELECT Emp_ID, Emp_Name, Emp_Salary FROM Emp; 17. Create a synonym of view object. CREATE SYNONYM SynonymName FOR ViewName; 18. Remove a view from Data Dictionary. DROP VIEW view_name; 19. Create an alias d for Dept table. SELECT * FROM Dept AS d; 20. Delete the recored of employee from Emp table.