











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!












Data entry error (during INSERT) Correctness (during UPDATE) Enforce consistency Tell system about the data (etc. uniqueness)
sID sName GPA HS sID^ uName^ major^ dec uName city enr University Student Apply Referential Integrity Referential integrity from R.A to S.B Each value in column A of table R must appear in column B of table S In our example database Each value in column sID of table Apply must appear in column sID of table Student
sID sName GPA HS sID^ uName^ major^ dec uName city enr Student Apply University Referential Integrity Referential integrity from R.A to S.B Each value in column A of table R must appear in column B of table S (^) A is called the “foreign key” (^) B is usually required to be the primary key for table S or at least unique (^) Multi-attribute foreign keys are allowed
Referential Integrity Referential Integrity Enforcement ( R.A to S.B ) Special actions: (^) Delete from S Restrict (default), Set Null , Cascade (^) Update S.B Restrict (default), Set Null , Cascade sID sName GPA HS sID^ uName^ major^ dec uName city enr Student Apply University
University ( uName , city , enrollment ) Student ( sID , sName , GPA , sizeHS ) Apply ( sID , uName , major , decision )
Student IDs are unique create table Student(sID int primary key, sName text, GPA real, sizeHS int);
University ( uName , city , enrollment ) Student ( sID , sName , GPA , sizeHS ) Apply ( sID , uName , major , decision )
create table Student(sID int primary key, sName text primary key, GPA real, sizeHS int); BUT ANY NUMBER OF UNIQUE KEYS create table Student(sID int primary key, sName text unique, GPA real, sizeHS int unique);
University ( uName , city , enrollment ) Student ( sID , sName , GPA , sizeHS ) Apply ( sID , uName , major , decision )
GPA and sizeHS are in range create table Student(sID int, sName text, GPA real check(GPA <= 4.0 and GPA > 0.0), sizeHS int check(sizeHS < 5000));
University ( uName , city , enrollment ) Student ( sID , sName , GPA , sizeHS ) Apply ( sID , uName , major , decision )
No CS admits to NUST create table Apply(sID int, uName text, major text, decision text, check(decision = 'N' or uName != ‘Comsats' or major != 'CS'));
University ( uName , city , enrollment ) Student ( sID , sName , GPA , sizeHS ) Apply ( sID , uName , major , decision )
create table Apply(sID int references Student(sID) on delete set null, uName text references University(uName) on update cascade, major text, decision text);
University ( uName , city , enrollment ) Student ( sID , sName , GPA , sizeHS ) Apply ( sID , uName , major , decision )