0% found this document useful (0 votes)
5 views19 pages

Lecture 3

Uploaded by

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

Lecture 3

Uploaded by

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

• CREATE DATABASE Company;

• -- Creating Company Schema


• USE Company;
• CREATE TABLE DEPARTMENT (
• dname varchar(25) not null,
• dnumber int not null primary key,
• CONSTRAINT pk_Department primary key (dnumber),
• CONSTRAINT uk_dname UNIQUE (dname),
• );
• CREATE TABLE EMPLOYEE (
• fname varchar(15) not null,
• minit varchar(1),
• lname varchar(15) not null,
• ssn char(9),
• bdate date,
• address varchar(50),
• sex char,
• salary decimal(10,2)
• dnumber int,
• supervisor_id INT,
• CONSTRAINT pk_employee primary key (ssn),
• CONSTRAINT fk_employee_department foreign key
(dnumber) references DEPARTMENT(dnumber),
CONSTRAINT fk_employee2_ EMPLOYEE foreign key
(ssn) references DEPARTMENT(ssn)
• FOREIGN KEY (supervisor_id) REFERENCES
Employee(employee_id) );
• );
• CREATE TABLE DEPENDENT (
• essn char(9),
• dependent_name varchar(15),
• sex char,
• bdate date,
• relationship varchar(8),
• CONSTRAINT pk_essn_dependent_name primary key (essn,dependent_name),
• CONSTRAINT fk_dependent_employee foreign key (essn) references EMPLOYEE(ssn)
• );
• CREATE TABLE PROJECT (
• pname varchar(25) not null,
• pnumber int,
• plocation varchar(15),
• dnum int not null,
• CONSTRAINT ok_project primary key (pnumber),
• CONSTRAINT uc_pnumber unique (pname),
• CONSTRAINT fk_project_department foreign key (dnum) references
DEPARTMENT(dnumber)
• );
• CREATE TABLE WORKS_ON (
• essn char(9),
• pno int,
• hours decimal(4,1),
• CONSTRAINT pk_worksOn primary key (essn,pno),
• CONSTRAINT fk_workson_employee foreign key
(essn) references EMPLOYEE(ssn),
• CONSTRAINT fk_workson_project foreign key (pno)
references PROJECT(pnumber)
• );
The END of the Lecture

for
Your Attention

You might also like