Explain the integrity constraints: Not Null, Unique, Primary Key with an example each. Is the combination 'Not Null, Primary Key' a valid combination. Justify.
Not Null - Should hold valid values and cannot be NULL.
Unique - An attribute or a combination of two or more attributes must have a unique value in each row. The unique key can have NULL values.
Primary Key - It is similar as unique key but cannot have NULL values. A table can have at most one primary key in it.
For example:
STUDENT
Roll No
|
Name
|
City
|
Mobile
|
17
|
Ankit Vats
|
Delhi
|
9891663808
|
16
|
Vivek rajput
|
Meerut
|
9891468487
|
6
|
Vanita
|
Punjab
|
NULL
|
75
|
Bhavya
|
delhi
|
9810618396
|
Roll No is a primary key.
Name is defined with NOT NULL, means each student must have a name.
'Not Null, Primary Key' is a valid combination. Primary key constraint already includes
'Not Null' constraint in it but we can also add 'Not Null' constraint with it. The use of
'Not Null' with 'Primary Key' will not have any effect. It is same as if we are using just 'Primary Key'.