Keys and Integrity Rules
Keys and Integrity Rules
What is a KEY ?
Key is a set of one or more columns whose combined values are unique among all occurrences in a given table.
Customer-street SSN Customer-city Customer-name customer
TYPES OF KEYS :
Super Key Candidate Key Primary Key Foreign Key Composite key
SUPER KEY:
A Super key is any combination of fields within a table that uniquely identifies each record within that table.
CANDIDATE KEY:
A candidate is a subset of a super key. A candidate key is a single field or the least combination of fields that uniquely identifies each record in the table.
PRIMARY KEY:
o Primary key is the candidate key which is most appropriate to become main key of the table. It uniquely identifies each record in the table. o A primary key can consist of more than one field. o Primary key attributes cannot take null values.
FOREIGN KEY:
Foreign keys are the attributes of a table, which refers to the primary key of some another table. Foreign keys are used to link together two or more different tables which have some form of relationship with each other.
COMPOSITE KEY:
Sometimes it requires more than one attribute to uniquely identify an entity. A primary key that is made up of more than one attribute is known as a composite key.
TYPES:
Entity Integrity Referential Integrity
ENTITY INTEGRITY
A Primary Key must have a unique value & null values are not allowed, i.e. Primary keys must be NOT NULL. For example:
Record number 3 and 5 violates the rule of primary key because the Rollno is primary key, all the value of attributes are unique but their primary key entries are NULL and this violates the integrity rule 1, so these records are not allowed in RDBMS.
REFERENTIAL INTEGRITY
Foreign key values must always be present in the set of primary key values to which they are associated, or be null. For example
It should not be possible to create a staff record with branch number B025, unless there is already a record for branch number B025 in the Branch relation. However, we should be able to create a new staff record with a null branch number, to cater for the situation where a new member of staff has joined the company but has not yet been assigned to particular branch office.
THANKYOU