SlideShare a Scribd company logo
Database keys
Introduction to Database Keys
Introduction to Database Keys
 Definition:
 A key in a database is an attribute or a set of attributes
that uniquely identifies a tuple (row) in a table.
 Importance:
 Ensures data integrity and uniqueness.
 Helps in indexing and fast retrieval of data.
 Facilitates relationships between tables.
Types of keys
 1. Primary Key
 2. Candidate Key
 3. Super Key
 4. Foreign Key
 5. Composite Key
 6. Alternate Key
 7. Unique Key
Primary key
 Definition: A column or a combination of columns that
uniquely identifies a row in a table.
 Characteristics:
 Must contain unique values.
 Cannot have NULL values.
 Only one primary key per table.
 Example:
CREATE TABLE Students ( StudentID INT PRIMARY KEY,
Name VARCHAR(100), Age INT);
Candidate key
 Definition: A set of attributes that can uniquely
identify a tuple, from which the primary key is
chosen.
 Example: If a table has StudentID and Email as
unique attributes, both are candidate keys, but
only one is chosen as the primary key.
Super key
 Definition: A set of one or more attributes that uniquely
identify a tuple in a table.
 Example:
 (StudentID)
 (StudentID, Email)
 (StudentID, Name, Email)
 All candidate keys are super keys, but not all super
keys are candidate keys.
Foreign key
 Definition: A key used to establish and enforce a link between two tables.
 Characteristics:
 References the primary key in another table.
 Can have duplicate and NULL values.
 Example:
 CREATE TABLE Enrollments ( EnrollmentID INT PRIMARY KEY, StudentID INT,
CourseID INT, FOREIGN KEY (StudentID) REFERENCES Students(StudentID));
Composite key
 Definition: A key that consists of two or more columns to uniquely identify a
row.
 Example: In an OrderDetails table, (OrderID, ProductID) together can act as a
composite key.
Alternate Key
 Definition: Candidate keys that are not chosen as the primary key.
 Example: If both StudentID and Email are candidate keys, but StudentID is
chosen as the primary key, Email becomes an alternate key.
Unique key
 Definition: Ensures uniqueness in a column but allows NULL values.
 Example:
 CREATE TABLE Employees ( EmpID INT PRIMARY KEY, Email VARCHAR(255)
UNIQUE);
Key Type Uniqueness NULL Allowed Can be Multiple?
Primary Key Yes No No
Candidate Key Yes No Yes
Super Key Yes Yes Yes
Foreign Key No Yes Yes
Composite Key Yes No Yes
Alternate Key Yes No Yes
Unique Key Yes Yes Yes
Comparision of keys
Summary
 Keys ensure data integrity, uniqueness, and relationships.
 Primary vs. Foreign Keys: Primary keys uniquely identify
rows, whereas foreign keys establish relationships.
 Candidate and Super Keys: All candidate keys are super
keys but not vice versa.
 Composite Keys consist of multiple columns.
Ad

Recommended

computer-210809080138.pdf
computer-210809080138.pdf
rahulsharma571283
 
Types Of Keys in DBMS
Types Of Keys in DBMS
PadamNepal1
 
Keys_in_DBMS_VALID_INFORMATION_IS_AVAILA
Keys_in_DBMS_VALID_INFORMATION_IS_AVAILA
prashantkori7
 
Types of keys in dbms
Types of keys in dbms
darshhingu
 
Keys in SQL.........................pptx
Keys in SQL.........................pptx
ejazayesha485
 
Copy of Templates ............. (1).pptx
Copy of Templates ............. (1).pptx
ejazayesha485
 
Copy of Templates & Apps............................. (1).pptx
Copy of Templates & Apps............................. (1).pptx
ejazayesha485
 
Presentation OF DBMS-2.pptx
Presentation OF DBMS-2.pptx
ShumailaSajjad
 
Dbms keys
Dbms keys
RUpaliLohar
 
Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)
Dr. SURBHI SAROHA
 
Dbms keysppt
Dbms keysppt
ArunakumariAkula1
 
key (1).pptx
key (1).pptx
KAnurag2
 
Keys.pptx
Keys.pptx
revathi s
 
Keys used in database
Keys used in database
university of Gujrat, pakistan
 
DBMS key topic Presentation slide 1.pptx
DBMS key topic Presentation slide 1.pptx
sonudhakad173
 
Types of keys in database | SQL
Types of keys in database | SQL
Sumit Pandey
 
DBMS VHGFGJKFHVGFJKHHFVHGFHBBVVHGVVHGVBVHG
DBMS VHGFGJKFHVGFJKHHFVHGFHBBVVHGVVHGVBVHG
umeshchandrekanti123
 
A Presentation of Types of Keys in RDBMS.pptx
A Presentation of Types of Keys in RDBMS.pptx
harman6895ala
 
B & c
B & c
Vaibhav Kathuria
 
DBMS Keys.pptx
DBMS Keys.pptx
AryanGour1
 
SQL_DBMS_KEYS.pptx
SQL_DBMS_KEYS.pptx
rahulsharma571283
 
Doc 20191022-wa0041
Doc 20191022-wa0041
university of Gujrat, pakistan
 
key.pptx
key.pptx
laptophp39
 
DBMS_Concept of Keys_Primary_Candidate.pdf
DBMS_Concept of Keys_Primary_Candidate.pdf
ssuser8af5d9
 
Keys in Database
Keys in Database
A. S. M. Shafi
 
KEYS IN DBMS.pptx soap ui kkeys and eclipse id
KEYS IN DBMS.pptx soap ui kkeys and eclipse id
LakshyaBaliyan2
 
DBMS_Keys.pdf
DBMS_Keys.pdf
DianneParaase
 
relational data model in RDBMS USING KEYS.pptx
relational data model in RDBMS USING KEYS.pptx
urvashipundir04
 
YEAP !NOT WHAT YOU THINK aakshdjdncnkenfj
YEAP !NOT WHAT YOU THINK aakshdjdncnkenfj
payalmistryb
 
11_L2_Defects_and_Trouble_Shooting_2014[1].pdf
11_L2_Defects_and_Trouble_Shooting_2014[1].pdf
gun3awan88
 

More Related Content

Similar to What are Database Keys in Database System (20)

Dbms keys
Dbms keys
RUpaliLohar
 
Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)
Dr. SURBHI SAROHA
 
Dbms keysppt
Dbms keysppt
ArunakumariAkula1
 
key (1).pptx
key (1).pptx
KAnurag2
 
Keys.pptx
Keys.pptx
revathi s
 
Keys used in database
Keys used in database
university of Gujrat, pakistan
 
DBMS key topic Presentation slide 1.pptx
DBMS key topic Presentation slide 1.pptx
sonudhakad173
 
Types of keys in database | SQL
Types of keys in database | SQL
Sumit Pandey
 
DBMS VHGFGJKFHVGFJKHHFVHGFHBBVVHGVVHGVBVHG
DBMS VHGFGJKFHVGFJKHHFVHGFHBBVVHGVVHGVBVHG
umeshchandrekanti123
 
A Presentation of Types of Keys in RDBMS.pptx
A Presentation of Types of Keys in RDBMS.pptx
harman6895ala
 
B & c
B & c
Vaibhav Kathuria
 
DBMS Keys.pptx
DBMS Keys.pptx
AryanGour1
 
SQL_DBMS_KEYS.pptx
SQL_DBMS_KEYS.pptx
rahulsharma571283
 
Doc 20191022-wa0041
Doc 20191022-wa0041
university of Gujrat, pakistan
 
key.pptx
key.pptx
laptophp39
 
DBMS_Concept of Keys_Primary_Candidate.pdf
DBMS_Concept of Keys_Primary_Candidate.pdf
ssuser8af5d9
 
Keys in Database
Keys in Database
A. S. M. Shafi
 
KEYS IN DBMS.pptx soap ui kkeys and eclipse id
KEYS IN DBMS.pptx soap ui kkeys and eclipse id
LakshyaBaliyan2
 
DBMS_Keys.pdf
DBMS_Keys.pdf
DianneParaase
 
relational data model in RDBMS USING KEYS.pptx
relational data model in RDBMS USING KEYS.pptx
urvashipundir04
 

Recently uploaded (20)

YEAP !NOT WHAT YOU THINK aakshdjdncnkenfj
YEAP !NOT WHAT YOU THINK aakshdjdncnkenfj
payalmistryb
 
11_L2_Defects_and_Trouble_Shooting_2014[1].pdf
11_L2_Defects_and_Trouble_Shooting_2014[1].pdf
gun3awan88
 
Indigo dyeing Presentation (2).pptx as dye
Indigo dyeing Presentation (2).pptx as dye
shreeroop1335
 
25 items quiz for practical research 1 in grade 11
25 items quiz for practical research 1 in grade 11
leamaydayaganon81
 
Boost Business Efficiency with Professional Data Entry Services
Boost Business Efficiency with Professional Data Entry Services
eloiacs eloiacs
 
MRI Pulse Sequence in radiology physics.pptx
MRI Pulse Sequence in radiology physics.pptx
BelaynehBishaw
 
定制OCAD学生卡加拿大安大略艺术与设计大学成绩单范本,OCAD成绩单复刻
定制OCAD学生卡加拿大安大略艺术与设计大学成绩单范本,OCAD成绩单复刻
taqyed
 
lecture12.pdf Introduction to bioinformatics
lecture12.pdf Introduction to bioinformatics
SergeyTsygankov6
 
Crafting-Research-Recommendations Grade 12.pptx
Crafting-Research-Recommendations Grade 12.pptx
DaryllWhere
 
Measurecamp Copenhagen - Consent Context
Measurecamp Copenhagen - Consent Context
Human37
 
NVIDIA Triton Inference Server, a game-changing platform for deploying AI mod...
NVIDIA Triton Inference Server, a game-changing platform for deploying AI mod...
Tamanna36
 
Model Evaluation & Visualisation part of a series of intro modules for data ...
Model Evaluation & Visualisation part of a series of intro modules for data ...
brandonlee626749
 
Residential Zone 4 for industrial village
Residential Zone 4 for industrial village
MdYasinArafat13
 
All the DataOps, all the paradigms .
All the DataOps, all the paradigms .
Lars Albertsson
 
ppt somu_Jarvis_AI_Assistant_presen.pptx
ppt somu_Jarvis_AI_Assistant_presen.pptx
MohammedumarFarhan
 
UPS and Big Data intro to Business Analytics.pptx
UPS and Big Data intro to Business Analytics.pptx
sanjum5582
 
PPT1_CB_VII_CS_Ch3_FunctionsandChartsinCalc.ppsx
PPT1_CB_VII_CS_Ch3_FunctionsandChartsinCalc.ppsx
animaroy81
 
最新版美国芝加哥大学毕业证(UChicago毕业证书)原版定制
最新版美国芝加哥大学毕业证(UChicago毕业证书)原版定制
taqyea
 
英国毕业证范本利物浦约翰摩尔斯大学成绩单底纹防伪LJMU学生证办理学历认证
英国毕业证范本利物浦约翰摩尔斯大学成绩单底纹防伪LJMU学生证办理学历认证
taqyed
 
Attendance Presentation Project Excel.pptx
Attendance Presentation Project Excel.pptx
s2025266191
 
YEAP !NOT WHAT YOU THINK aakshdjdncnkenfj
YEAP !NOT WHAT YOU THINK aakshdjdncnkenfj
payalmistryb
 
11_L2_Defects_and_Trouble_Shooting_2014[1].pdf
11_L2_Defects_and_Trouble_Shooting_2014[1].pdf
gun3awan88
 
Indigo dyeing Presentation (2).pptx as dye
Indigo dyeing Presentation (2).pptx as dye
shreeroop1335
 
25 items quiz for practical research 1 in grade 11
25 items quiz for practical research 1 in grade 11
leamaydayaganon81
 
Boost Business Efficiency with Professional Data Entry Services
Boost Business Efficiency with Professional Data Entry Services
eloiacs eloiacs
 
MRI Pulse Sequence in radiology physics.pptx
MRI Pulse Sequence in radiology physics.pptx
BelaynehBishaw
 
定制OCAD学生卡加拿大安大略艺术与设计大学成绩单范本,OCAD成绩单复刻
定制OCAD学生卡加拿大安大略艺术与设计大学成绩单范本,OCAD成绩单复刻
taqyed
 
lecture12.pdf Introduction to bioinformatics
lecture12.pdf Introduction to bioinformatics
SergeyTsygankov6
 
Crafting-Research-Recommendations Grade 12.pptx
Crafting-Research-Recommendations Grade 12.pptx
DaryllWhere
 
Measurecamp Copenhagen - Consent Context
Measurecamp Copenhagen - Consent Context
Human37
 
NVIDIA Triton Inference Server, a game-changing platform for deploying AI mod...
NVIDIA Triton Inference Server, a game-changing platform for deploying AI mod...
Tamanna36
 
Model Evaluation & Visualisation part of a series of intro modules for data ...
Model Evaluation & Visualisation part of a series of intro modules for data ...
brandonlee626749
 
Residential Zone 4 for industrial village
Residential Zone 4 for industrial village
MdYasinArafat13
 
All the DataOps, all the paradigms .
All the DataOps, all the paradigms .
Lars Albertsson
 
ppt somu_Jarvis_AI_Assistant_presen.pptx
ppt somu_Jarvis_AI_Assistant_presen.pptx
MohammedumarFarhan
 
UPS and Big Data intro to Business Analytics.pptx
UPS and Big Data intro to Business Analytics.pptx
sanjum5582
 
PPT1_CB_VII_CS_Ch3_FunctionsandChartsinCalc.ppsx
PPT1_CB_VII_CS_Ch3_FunctionsandChartsinCalc.ppsx
animaroy81
 
最新版美国芝加哥大学毕业证(UChicago毕业证书)原版定制
最新版美国芝加哥大学毕业证(UChicago毕业证书)原版定制
taqyea
 
英国毕业证范本利物浦约翰摩尔斯大学成绩单底纹防伪LJMU学生证办理学历认证
英国毕业证范本利物浦约翰摩尔斯大学成绩单底纹防伪LJMU学生证办理学历认证
taqyed
 
Attendance Presentation Project Excel.pptx
Attendance Presentation Project Excel.pptx
s2025266191
 
Ad

What are Database Keys in Database System

  • 2. Introduction to Database Keys  Definition:  A key in a database is an attribute or a set of attributes that uniquely identifies a tuple (row) in a table.  Importance:  Ensures data integrity and uniqueness.  Helps in indexing and fast retrieval of data.  Facilitates relationships between tables.
  • 3. Types of keys  1. Primary Key  2. Candidate Key  3. Super Key  4. Foreign Key  5. Composite Key  6. Alternate Key  7. Unique Key
  • 4. Primary key  Definition: A column or a combination of columns that uniquely identifies a row in a table.  Characteristics:  Must contain unique values.  Cannot have NULL values.  Only one primary key per table.  Example: CREATE TABLE Students ( StudentID INT PRIMARY KEY, Name VARCHAR(100), Age INT);
  • 5. Candidate key  Definition: A set of attributes that can uniquely identify a tuple, from which the primary key is chosen.  Example: If a table has StudentID and Email as unique attributes, both are candidate keys, but only one is chosen as the primary key.
  • 6. Super key  Definition: A set of one or more attributes that uniquely identify a tuple in a table.  Example:  (StudentID)  (StudentID, Email)  (StudentID, Name, Email)  All candidate keys are super keys, but not all super keys are candidate keys.
  • 7. Foreign key  Definition: A key used to establish and enforce a link between two tables.  Characteristics:  References the primary key in another table.  Can have duplicate and NULL values.  Example:  CREATE TABLE Enrollments ( EnrollmentID INT PRIMARY KEY, StudentID INT, CourseID INT, FOREIGN KEY (StudentID) REFERENCES Students(StudentID));
  • 8. Composite key  Definition: A key that consists of two or more columns to uniquely identify a row.  Example: In an OrderDetails table, (OrderID, ProductID) together can act as a composite key. Alternate Key  Definition: Candidate keys that are not chosen as the primary key.  Example: If both StudentID and Email are candidate keys, but StudentID is chosen as the primary key, Email becomes an alternate key.
  • 9. Unique key  Definition: Ensures uniqueness in a column but allows NULL values.  Example:  CREATE TABLE Employees ( EmpID INT PRIMARY KEY, Email VARCHAR(255) UNIQUE);
  • 10. Key Type Uniqueness NULL Allowed Can be Multiple? Primary Key Yes No No Candidate Key Yes No Yes Super Key Yes Yes Yes Foreign Key No Yes Yes Composite Key Yes No Yes Alternate Key Yes No Yes Unique Key Yes Yes Yes Comparision of keys
  • 11. Summary  Keys ensure data integrity, uniqueness, and relationships.  Primary vs. Foreign Keys: Primary keys uniquely identify rows, whereas foreign keys establish relationships.  Candidate and Super Keys: All candidate keys are super keys but not vice versa.  Composite Keys consist of multiple columns.