5 Slide
5 Slide
PRESENTATION
DIFFERENT TYPES OF KEYS
IN DATABASE
SUBMITED BY:
PADAM NEPAL
029/074
6TH SEM
TABLE OF CONTENT
• KEYS
– TYPES OF KEYS
I. SUPER KEY: EXAMPLE
II. CANDIDATE KEY: PROPERTIES/DIFFERENCE
III. PRIMARY KEY: EXAMPLE/RULES
IV. ALTERNATE KEY
V. UNIQUE KEY
VI. COMPOSITE KEY
VII. FOREIGN KEY
VIII.NATURAL KEY
IX. SURROGATE KEY
X. CONCLUSION
KEYS
• KEYS in DBMS is an attribute or set of attributes which helps you to
identify a row(tuple) in a relation(table).
• They allow you to find the relation between two tables.
• Keys help you uniquely identify a row in a table by a combination of one or
more columns in that table.
• Key is also helpful for finding unique record or row from the table.
• It is used to fetch or retrieve records / data-rows from data table
according to the condition/requirement.
STU ID NAME SUBJECT
• A table can have multiple choices for a primary key but only one
can be set as the primary key. All the keys which are not primary
key are called an Alternate Key.
• Alternate keys are candidate keys that are not selected as primary
key. Alternate key can also work as a primary key. Alternate key is
also called “Secondary Key”.
Example:
Alternate Key in college_Info table:
• college_Name
• college_Code
• Alternate Key in Student_Information table:
• Student_Id
• stu_Roll_No
Unique Key:
• A unique key is a set of one or more attribute that can be used to
uniquely identify the records in table. Unique key is similar to
primary key but unique key field can contain a “Null” value but
primary key doesn’t allow “Null” value. Other difference is that
primary key field contain a clustered index and unique field contain
a non-clustered index.
Example:
Possible Unique Key in college_Info table.
• college_Name
• Possible Unique Key in Student_Information table:
• stu_Roll_No
Composite Key:
• Composite key is a combination of more than one
attributes that can be used to uniquely identity each
record. It is also known as “Compound” key. A composite
key may be a candidate or primary key.
Example:
Composite Key in college_Info table.
• { Branch_Name, Branch_Code}
Composite Key in Student_Information table:
• { Student_Id, Student_Name }
Foreign Keys:
• Foreign key is used to generate the relationship between the tables.
Foreign Key is a field in database table that is Primary key in
another table. A foreign key can accept null and duplicate value.
• The purpose of Foreign keys is to maintain data integrity and allow
navigation between two different instances of an entity. It acts as a
cross-reference between two tables as it references the primary key
of another table.
• Foreign keys are the columns of a table that points to the primary
key of another table.
Example:
university_Id is a Foreign Key in Student_Information table that
primary key exist in college_Info(university_Id) table.
Cont.