0% found this document useful (0 votes)
23 views20 pages

Primary and Foriegn Key

Uploaded by

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

Primary and Foriegn Key

Uploaded by

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

Sid sname sbranch semail are attributes

Sid and semail are keys which are unique


By making attribute a key and making it mandatory

Super key

Every key in a table is a super key


SID REG_ID NAME BRANCH EMAIL
1 CS-2019-37 JOHN CS [email protected]
2 CS-2018-02 ADAM CS [email protected]
3 IT-2019-01 ADAM IT
4 ECE-2019-07 ELLY ECE [email protected]

 SID SID+REG_ID SID+REG_ID+EMAIL


 REG_ID REG_ID+EMAIL
 EMAIL EMAIL+SID
SUPER KEYS
PROPER SUBSET OF SUPER KEY AND IS ALSO A SUPER KEY

 SID SID+REG_ID SID+REG_ID+EMAIL-


 REG_ID REG_ID+EMAIL NOT CANDIDATE KEY
 EMAIL EMAIL+SID



 SID SID+REG_ID-NOT A CANDIDATE KEY
SID+REG_ID+EMAIL
 REG_ID REG_ID+EMAIL
 EMAIL EMAIL+SID
HENCE SID REG_ID EMAIL ARE CANDIDTE KEYS
REG_ID is taken as primary key in this example
All other candidate keys like sid name branch email are not
selected as primary key are called alternate keys

We can select primary keys among candidate keys

REG_ID PRIMARY KEYS


Primary key
Uniquely identified the rows
1 table can have 1 primary key only
It must not be null
Have to keep a value cannot restrict value in column
Primary key to supplier id
Constraint pk1 user defined primary key
Constraint not use reserve key or keywords
Supplier id cannot insert duplicate value
Without defining constraint key you can write primary key

Alter table

If column is not exist we will write


Value in one table also appears in another table

Foreign key

Constraint name is fixed

You might also like