dbms-lab
dbms-lab
PUT_LINE(result);
c NUMBER; END; /
i NUMBER;
ELSE
-- Step 2: Insert Sample Data (if table is empty) WHEN OTHERS THEN
check_even_odd(25);
SELECT 102, 'Jane Smith', 60000, 3 FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM employee
END; WHERE emp_id = 102);
/
INSERT INTO project (Pname, Pnumber, Plocation, SELECT d.Dnumber
Dnum)
FROM Department d
create schema 23mis7253;
VALUES
WHERE d.Dname = 'Research'
use 23mis7253;
('Delta', 16, 'Chennai', 4);
);
CREATE TABLE employee (
-- Create works_on table
-- 6)For every project located in 'Stafford', list the
Fname varchar(15) NOT NULL, Minit
CREATE TABLE works_on ( project number, the controlling department
varchar(1),
number, and the department manager's last
Essn varchar(9) NOT NULL, name, address, and birthdate:
Lname varchar(15) NOT NULL,
Pno int NOT NULL, Hours float NOT NULL, SELECT P.Pnumber, P.Dnum, D.Mgr_Ssn, E.Lname,
SSN varchar(20) NOT NULL, E.Address, E.Bdate
PRIMARY KEY (Essn, Pno),
Bdate date, Address varchar(30), FROM PROJECT P, DEPARTMENT D, EMPLOYEE E
FOREIGN KEY (Essn) REFERENCES
Sex varchar(1), Salary float, WHERE P.Plocation = 'Chennai'
employee(SSN),
INSERT INTO employee (Fname, Minit, Lname, where Dnumber =(select Dnumber from
-- Create dependent table
SSN, Bdate, Address, Sex, Salary, Super_ssn, Dno) department where Dname='Research' or 'HR');
CREATE TABLE dependent (
VALUES -- 8) Find the employee who has no supervisor
Essn varchar(9) NOT NULL,
('David', 'T', 'Miller', '159753456', '1975-09-11', select Fname from employee
'101 Maple Ave, Seattle, WA', 'M', 75000.0,
Dependent_name varchar(15) NOT NULL,
'741852963', 1);
where super_ssn is NULL;
Sex varchar(1),
CREATE TABLE department (
-- 9)Retrieve the name of each employee who has
a dependent with the same first name as the
Bdate date,
Dname varchar(15) NOT NULL, Dnumber int employee:
NOT NULL,
Relationship varchar(8),
SELECT e.Fname, e.Lname FROM employee e
Mgr_ssn varchar(9) NOT NULL, Mgr_start_date
date, PRIMARY KEY (Essn, Dependent_name),
WHERE e.Fname IN (SELECT d.Dependent_name
FROM dependent d );
PRIMARY KEY (Dnumber), UNIQUE (Dname), FOREIGN KEY (Essn) REFERENCES
employee(SSN)
-- WEEK3-----
FOREIGN KEY (Mgr_ssn) REFERENCES
employee(SSN) );
-- 1)For each employee retrieve employee's name
and name of his/her supervisor
); INSERT INTO dependent (Essn, Dependent_name,
Sex, Bdate, Relationship)
SELECT E.Fname, E.Lname, S.Fname, S.Lname
INSERT INTO department (Dname, Dnumber, FROM EMPLOYEE E, EMPLOYEE S
Mgr_ssn, Mgr_start_date) VALUES
);
WHERE e.Dno IN (
-- 5)Retrieve the social security numbers of all WHERE Bdate LIKE '198_--';
employees who work on project numbers 12, 13,
or 14: -- 8) Display department names that start with 'R'
-- Experiment 5 ---
ORDER BY E.Dno;
select count(*),pname,project.pnumber
from project,works_on
where project.pnumber=works_on.pno
group by project.pnumber
having count(*)>2;