ADVANCED DATABASE
LAB PROJECT
Group Member
1. CHERNET ALEMU RCS/1320/12
2. DEBORAH GETSCHEW RCS/1956/12
3. KIDIST MARKOS RCS/2010/12
1) To display the REGION_NAME and COUNTRY_NAME using NATURAL JOIN
ANS
SELECT REGION_NAME, COUNTRY_NAME FROM REGIONS NATURAL JOIN COUNTRIES;
2) To display JOB_TITLE and LAST_NAME using LEFT OUTER JOIN
ANS
SELECT E.LAST_NAME, J.JOB_TITLE FROM EMPLOYEES E LEFT OUTER JOIN JOBS ON (E.JOB_ID = E.JOB_ID);
3) To display JOB_TITLE and LAST_NAME using FULL OUTER JOIN
ANS
SELECT E.LAST_NAME, J.JOB_TITLE FROM EMPLOYEES E FULL OUTER JOIN JOBS J ON (E.JOB_ID = E.JOB_ID);
4) To display JOB_TITLE, LAST_NAME as a Cartesian product
ANS
SELECT last_name, JOB_TITLE FROM employees CROSS JOIN JOBS ;
5) To display the DEPARTMENT-ID, MANAGER-ID of those employees who are assigned
and managing a certain department [hint: use a set operator
ANS
SELECT DEPARTMENT_ID, MANAGER_ID FROM employees INTERSECT SELECT
DEPARTMENT_ID, MANAGER_ID FROM DEPARTMENTS;
6) To display LAST-NAME and SALARY of employees whose salary is >= the average
salary of all employees[use multiple row subqueries
ANS
SELECT last_name, salary FROM employees WHERE salary < ALL (SELECT salary FROM employees WHERE
job_id = '>=') ;
7) To display the DEPARTMENT-ID, minimum and maximum salary of each department
employees.
ANS
Select DEPARTMENT_ID max (salary) as MaxSalary, min(Salary) as Minsalary from EMPLOYEES group by
DEPARTMENT_ID
8) To define SAVEPOINT [you can give it any name] over the department table. Make
the save point appear after a DELETE statement of a record deletion and before one
UPDATE and one INSERT statement. Then write a Rollback statement to your
defined savepoint.
ANS
SELECT * FROM hr.employees;
Delete from hr.DEPARTMENTS where DEPARTMENT_ID='400';
SAVEPOINT Ydelete;
SELECT * FROM hr.DEPARTMENTS;
SAVEPOINT YInsert;
INSERT INTO hr.DEPARTMENTS VALUES ( 400 , 'IT_Admin' , null , null );
SELECT * FROM hr.DEPARTMENTS;
SAVEPOINT HUPDATE;
UPDATE hr.DEPARTMENTS set DEPARTMENT_NAME='H_ADMIN' where DEPARTMENT_ID='400';
SELECT * FROM hr.DEPARTMENTS;
ROLLBACK TO SAVEPOINT HUPDATE;
9) To create a role and a user [you can give it any name you want]
ANS
CREATE USER H1s_proj IDENTIFIED BY abc;
CREATE ROLE H1srole1;
10) To assign the user to the defined role
ANS
GRANT role TO H1s_proj;
11) To give update privilege on the salary field of employee table for the user
created with permission propagation privilege
ANS
GRANT UPDATE ON HR.EMPLOYEES TO H1s_proj WITH GRANT OPTION;
GRANT UPDATE(Salary) ON HR.EMPLOYEES TO H1s_proj
12) To give a privilege of selecting, inserting, and deleting of records to the
department table for the role you have created
ANS
SELECT, INSERT, DELETE ON hr.countries TO role1;
13) To give a privilege of selecting LAST-NAME,DEPARTMENT-NAME,SALARY of
Finance department employees for the role you have created [hint : create view
first]
ANS
CREATE VIEW H1s_proj DEPARTMENT AS SELECT LAST_NAME, DEPARTMENT_NAME, SALARY
FROM HR.DEPARTMENTS, HR.EMPLOYEES WHERE DEPARTMENT_NAME = ‘finance’;
GRANT SELECT ON H1s_proj DEPARTMENTS TO role1 with GRANT OPTION;
14) To deny the inserting privilege from your role
ANS
REVOKE INSERT ON hr.employees FROM role1;
15) To delete the role and user created
ANS
REVOKE INSERT ON hr.employees FROM role1;