Experiment 6 Applying Constraints (Column Level, Table Level)

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Experiment 6

Applying Constraints (Column level, Table


level)
Constraints (for Relational model):- Create table tablename (att1 CONSTRAINT1, att2
CONSTRAINT 2, att3 REFERENCES tablename2)
- Alter table tablename ADD CONSTRAINT (att1)
- To remove attribute constraints, drop the attribute
Syntax: - drop att11;
- Primary Key
- Foreign Key
- Not Null
- Unique: - can be null as opposed to primary key.
- Check: - checks the value of given attribute
- Default: -

Q) Create the following tables and apply the given


constraints:i) Employee: (E_no Primary key, E_name Not Null, Sal check>1000,
dept_no foreign key)
ii) Department: (Dept_no Primary key, D_name Not Null) : (Add
constraint through Alter)
iii) Project: ( Project_no Primary key, project_name NOT NULL,
Location, Dept_no Foreign Key)
iv) Works On: (E_no Foreign Key, Project_no Foreign Key, new column
(E_no, Project_no) Primary Key)

EMPLOYEE

E_Name

SSN(*)

DOB

DEPARTMENT
DEPTT_LOCATI
ON
PROJECT

D_Name
D_No**(*
)
P_Name

D_No(*)
D_Location(
*)
P_No(*)

Man_No

WORKS_ON

ES_Sn**(
*)
ES_Sn**

P_No**(*)

DEPENDENT

Dependent
Name(*)

Sex

P_Locatio
n
Hours

D_N
o**

Sex

DOB

Salary

Super_
SSN**

Realtions
hip

i) Employee: (E_no Primary key, E_name Not Null, Sal check>1000,


dept_no foreign key)

D_N
o**

ii) Department: (Dept_no Primary key, D_name Not Null) : (Add


constraint through Alter)
iii) Project: ( Project_no Primary key, project_name NOT NULL,
Location, Dept_no Foreign Key)
iv) Works On: (E_no Foreign Key, Project_no Foreign Key, new column
(E_no, Project_no) Primary Key)

You might also like