0% found this document useful (0 votes)
24 views2 pages

DBMS Lab 2

The document contains SQL commands to create three tables: department, employee, and dependent, with specified fields and primary/foreign key constraints. It also includes several INSERT statements to add dependent records for employees and UPDATE statements to modify employee salary and department manager information. The structure supports a relational database for managing employee and department data along with their dependents.

Uploaded by

stamim223689
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

DBMS Lab 2

The document contains SQL commands to create three tables: department, employee, and dependent, with specified fields and primary/foreign key constraints. It also includes several INSERT statements to add dependent records for employees and UPDATE statements to modify employee salary and department manager information. The structure supports a relational database for managing employee and department data along with their dependents.

Uploaded by

stamim223689
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

CREATE TABLE department (

dname VARCHAR(20),
dnumber INT NOT NULL,
mgrssn INT,
mgrstartdate DATE,
PRIMARY KEY (dnumber)
);

CREATE TABLE employee (


fname VARCHAR(15),
minit VARCHAR(2),
lname VARCHAR(15),
ssn INT(12) NOT NULL,
bdate DATE,
address VARCHAR(35),
gender VARCHAR(1),
salary INT(7) NOT NULL,
superssn INT(12),
dno INT NOT NULL,
PRIMARY KEY (ssn),
CONSTRAINT fk_dno_dnumber FOREIGN KEY (dno) REFERENCES
department (dnumber)
);

CREATE TABLE dependent (


essn INT,
dependent_name VARCHAR(15),
gender VARCHAR(1),
bdate DATE,
relationship VARCHAR(12),
PRIMARY KEY (essn, dependent_name),
CONSTRAINT fk_essn_ssn FOREIGN KEY (essn) REFERENCES employee
(ssn)
);

INSERT INTO dependent VALUES (333445555,'ALICE','F','1976-04-05','DAUGHTER');


INSERT INTO dependent VALUES (333445555,'THEODORE','M','1973-10-25','SON');
INSERT INTO dependent VALUES (333445555,'JOY','F','1948-05-03','SPOUSE');
INSERT INTO dependent VALUES (123456789,'MICHAEL','M','1978-01-01','SON');
INSERT INTO dependent VALUES (123456789,'ALICE','F','1978-12-31','DAUGHTER');
INSERT INTO dependent VALUES (123456789,'ELIZABETH','F','1957-05-05','SPOUSE');
INSERT INTO dependent VALUES (987654321,'ABNER','M','1932-02-26','SPOUSE');

UPDATE employee
SET salary = 35000
WHERE ssn = 123456789;

UPDATE department
SET mgrssn = 987987987
WHERE dname = 'RESEARCH';

You might also like