DBMS & Gui Lab Manual
DBMS & Gui Lab Manual
EXERCISE 5
(iii)
(a)Retrieve all the attribute values of any EMPLOYEE who works in DEPARTMENT
number 4.
SELECT * FROM employee WHERE dno = 4;
(c)Retrieve all the attribute values of employees whose salary is greater than or equal to
20000.
SELECT * FROM employee WHERE salary >= 20000;
(iv)Retrieve the birth date and address of the employee(s) whose name is ‘John B. Smith’.
SELECT bdate, address
FROM employee
WHERE fname=‘John’ AND minit=‘B’ AND lname=‘Smith’;
(v)Retrieve the name and address of all employees who work for the ‘Research’
department.
SELECT fname, lname, address
FROM employee, department
WHERE dnumber=dno AND dname=‘Research’;
Ex. No. 8 (ORDER BY clause)
(ii) Retrieve first name, last name, date of birth of employees who are managers along with
the name of the department that they manage.
SELECT fname, lname, bdate, dname
FROM employee, department
WHERE ssn = mgr_ssn
ORDER BY bdate;
(iii) Retrieve a list of employees and the projects they are working on, ordered by
department (descending) and, within each department, ordered alphabetically by last name
(ascending), then first name (ascending).
SELECT D.dname, E.lname, E.fname, P.pname
FROM department D, employee E, works_on W, project P
WHERE D.dnumber= E.dno AND E.ssn= W.essn AND W.pno= P.pnumber
ORDER BY D.dname DESC, E.lname ASC, E.fname ASC;
Ex. No. 10 (Aggregate functions in SQL (Count, Sum, Max, Min, Avg))
(i) Find the sum of salary, maximum salary, minimum salary, and average salary of all
employees.
SELECT SUM (salary), MAX (salary), MIN (salary), AVG (salary) FROM employee;
SELECT COUNT(*)
FROM employee, department
WHERE dno = dnumber AND dname = 'Research';
(iii) Show the resulting salaries if every employee working in the research department is
given a 10 percent raise.
(i) Retrieve name and address of employees working in the research department.
(ii) For every project located in Stafford, list the project number, the controlling
department number, and the department manager's last name, address, and birth date.
(ii) Retrieve the names of employees whose salary is greater than the salary of all the
employees in department 5.
(iv) List the names of managers who have at least one dependent.
SELECT fname, lname
FROM employee
WHERE EXISTS ( SELECT *
FROM dependent
WHERE ssn=essn )
AND
EXISTS ( SELECT *
FROM department
WHERE ssn=mgr_ssn );
(i) Create a view 'works_on1' to store employee's first and last name, projects they have
worked on, and the number of hours they worked on each project.
TCL Command
Transaction Control Language (TCL) commands are used to manage transactions (collection of
queries) in database. These are used to manage the changes made by DML statements.
COMMIT - This command is used to permanently save any transaction into database.
SAVEPOINT - This command is used to temporarily save a transaction so that you can
rollback to that point whenever necessary.
ROLLBACK - This command restores the database to last committed state. It is also used
with savepoint command to jump to a savepoint in a transaction.
Consider the 'students' table and its data in Ex. No. 14
Q5. COMMIT;
(After COMMIT, transaction made using Q2 and Q3 will be permanently saved in the database.)
Q8. SAVEPOINT a;
Q11. SAVEPOINT b;
Q13. ROLLBACK to b;
(This command will remove the transaction made using Q12.)
Q14. COMMIT;
(This command will make permanent all the transactions made using Q6,Q7,Q9, and Q10.)