Database_Keys types of keys in DBMS.pptx

AaashaRana 193 views 11 slides Jul 17, 2024
Slide 1
Slide 1 of 11
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11

About This Presentation

Keys in Databases
An attribute or set of attributes that uniquely identifies a tuple in a relation.
Different types of keys used in databases are as follows:
PRIMARY KEY
COMPOSITE / CONCATENATE KEY
CANDIDATE KEY
ALTERNATE KEY
FOREIGN KEY
SECONADRY KEY
SORT/CONTROL KEY


Slide Content

Keys in Databases Different types of keys used in databases

What is a key?

Types of Keys Different types of keys used in databases are as follows: PRIMARY KEY COMPOSITE / CONCATENATE KEY CANDIDATE KEY ALTERNATE KEY FOREIGN KEY SECONADRY KEY SORT/CONTROL KEY

1. Primary Key An attribute or set of attributes that uniquely identifies a row or record in a relation is known as primary key. Some most important points about a primary key are as follows: A relation can have only one primary key. Each value in primary key attribute must be unique. Primary key cannot contain null values. Example:

2. Composite Key / Concatenate Key A primary key that consists of two or more attributes is known as composite key. Example: The following relation uses two attributes RollNo and Subject to identify each tuple. This is an example of composite key.

3. Candidate Key A relation may contain many attributes or sets of attributes that can be used as primary key. The attribute or set of attributes that can be used as primary key is called candidate key. Example:

4. Alternate Key The candidate keys that are not selected as primary key are known as alternate keys. Example:

5. Foreign Key A foreign key is an attribute or set of attributes in a relation whose values match a primary key in another relation. The relation in which foreign key is created is known as dependent relation or child relation. The relation to which the foreign key refers is known as parent relation . The key connects to another relation when a relationship is established between two relations. A relation may contain many foreign keys.

Foreign Key Example The following figure shows two relations. The RollNo attribute in Parent relation is used as primary key. The RollNo attribute in Child relation is used as foreign key. It refers to RollNo attribute in Parent relation.

6. Secondary Key

7. Sort / Control Key An attribute or set of attributes that is used to physically sequence the stored data is called sort key. It is also known as control key. The stored data can be sorted in different ways according to the user requirement.