Pr.Pg Next Pg

Keys tutorials

 

Key attributes play a “KEY” role in relationship and in the ER Model. There are 2 types of keys, i.e.

1)      PRIMARY KEY

2)      FOREIGN KEY

 

PRIMARY KEY (PK)

  • The primary key is an attribute or a set of attribute identifying unique instance of each entity. For example an Invoice number identify every invoice created by specific company, student Roll no specify unique roll no of student for exam, Bank account operator have bank Account number, International tourist need Passport with unique Passport number.

  • In all above example Invoice no for company, Student roll number, Bank account number of account holder and Passport number is unique number. We therefore can create it as PRIMARY KEY.

  • PRIMARY key may have single entity (Attribute) or multiple entities (attributes). If a Primary key is made of multiple attributes, it is said to be COMPOSITE. Besides the fact of being an attribute or a set of attributes, a primary key must have following properties to identify every instance.

  • Every attribute must have a value. That means that attribute composing the primary key cannot be null.

  • The value of the key must be unique for every instance of the entity. If the Primary key is made of composite, every group of attribute values has to be unique.

 

FOREIGN KEY (FK)

  • A foreign key is an attribute or a set of attributes that identifies the child side of a relationship. A foreign key is in fact the “Migrating” Primary key of the parent entity. If we set Primary – foreign key relationship between CUSTOMER and ORDER table, then CUSTOMERID will be found in ORDER table as well as CUSTOMER table.

  • Two tables can be related using a common attribute or entity. When a primary key of one table is also available as an attributed of another related table, it is called FOREIGN KEY.

  • Primary key and Foreign key in following example.

 

 


Pr.Pg border                                              Next Pg