SlideShare a Scribd company logo
1 of 20
“TRIBHUVAN UNIVERSITY”
DEPARTMENT OF PUBLIC ADMINISTRATION
PUBLIC ADMINISTRATION CAMPUS
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
29/074 PADAM NEPAL COMPUTER
10/074 JANAK BHANDARI COMPUTER
TYPES OF KEYS
Super key in DBMS
• A super key is a set of one or more attributes
(columns), which can uniquely identify a row in a table.
• A Super key for an entity is a set of one or more
attributes whose combined value uniquely identifies
the entity in the entity set.
• A super key is a combine form of Primary Key,
Alternate key and Unique key and Primary Key, Unique
Key and Alternate Key are subset of super key.
• A Super Key is simply a non-minimal Candidate Key,
that is to say one with additional columns not strictly
required to ensure uniqueness of the row. A super key
can have a single column.
example
• Example:
Super Keys in college_Info Table.
• university_Id
• college_Name
• college_Code
• { university_Id, college_Code }
• { college_Name , college_Code }
Super Keys in Student_Information Table:
• Student_Id
• College_Id
• stu_Roll_No
• { Student_Id, Student_Name}
• { College_Id, Branch_Id }
• { stu_Roll_No, Session }
Candidate Key
• A Candidate key is an attribute or set of attributes that uniquely identifies
a record. Among the set of candidate, one candidate key is chosen as
Primary Key. So a table can have multiple candidate key but each table can
have maximum one primary key.
• a candidate key is a minimal super key with no redundant attributes.
Example:
Possible Candidate Keys in college_Info table.
• university_Id
• college_Name
• college_Code
• Possible Candidate keys in Student_Information table.
• Student_Id
• College_Id
• stu_Rollno
Properties of Candidate key
• It must contain unique values
• Candidate key may have multiple attributes
• Must not contain null values
• It should contain minimum fields to ensure
uniqueness
• Uniquely identify each record in a table
How candidate key is different from super
key?
• Candidate keys are selected from the set of
super keys, the only thing we take care while
selecting candidate key is: It should not have
any redundant attribute. That’s the reason
they are also termed as minimal super key.
• all the candidate keys are super keys. This is
because the candidate keys are chosen out of
the super keys.
Primary Key
• A Primary key uniquely identifies each record in a table
and must never be the same for the 2 records.
• Primary key is a set of one or more fields ( columns) of
a table that uniquely identify a record in database
table.
• A table can have only one primary key and one
candidate key can select as a primary key.
• The primary key should be chosen such that its
attributes are never or rarely changed, for example, we
can’t select Student_Id field as a primary key because
in some case Student_Id of student may be changed
Primary key examples
• Primary Key in college_Info table:
• university_Id
• Primary Key in Student_Information Table:
• College_Id
Rules for defining Primary key:
• Two rows can't have the same primary key
value
• It must for every row to have a primary key
value.
• The primary key field cannot be null.
• The value in a primary key column can never
be modified or updated if any foreign key
refers to that primary key.
What is the Alternate key?
• 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.
• Practically, the foreign key has nothing to do
with the primary key tag of another table, if it
points to a unique column (not necessarily a
primary key) of another table then too, it
would be a foreign key. So, a correct definition
of foreign key would be: Foreign keys are the
columns of a table that points to
the candidate key of another table.
Natural Keys:
A natural key is a key composed of columns that
actually have a logical relationship to other
columns within a table. For example, if we use
Student_Id, Student_Name and Father_Name
columns to form a key then it would be “Natural
Key” because there is definitely a relationship
between these columns and other columns that
exist in table. Natural keys are often called
“Business Key ” or “Domain Key”.
Surrogate Key:
• Surrogate key is an artificial key that is used to
uniquely identify the record in table. For
example, in SQL Server or Sybase database
system contain an artificial key that is known
as “Identity”. Surrogate keys are just simple
sequential number. Surrogate keys are only
used to act as a primary key.
Conclusion
• Database generally only contain Primary Key,
Foreign Key, Unique Key and Surrogate key and
other remaining keys are just concept. A table
must have a unique key. According to Dr. E. F.
Codd ‘s third rule “Every single data element
(value) is guaranteed to be accessible logically
with a combination of table-name, primary-key
(row value), and attribute-name (column value)”.
So each table must have keys , because use of
keys make data highly reliable and provide
several types of content like unique data and null
values.

More Related Content

What's hot

Database abstraction
Database abstractionDatabase abstraction
Database abstractionRituBhargava7
 
Key and its different types
Key and its different typesKey and its different types
Key and its different typesUmair Shakir
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)Sharad Dubey
 
Types of keys in dbms
Types of keys in dbmsTypes of keys in dbms
Types of keys in dbmsdarshhingu
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational modelChirag vasava
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In SqlAnurag
 
SQL commands
SQL commandsSQL commands
SQL commandsGirdharRatne
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model IntroductionNishant Munjal
 
All data models in dbms
All data models in dbmsAll data models in dbms
All data models in dbmsNaresh Kumar
 
Create table
Create tableCreate table
Create tableNitesh Singh
 
Er model ppt
Er model pptEr model ppt
Er model pptPihu Goel
 
SQL Joins.pptx
SQL Joins.pptxSQL Joins.pptx
SQL Joins.pptxAnkit Rai
 
Group By, Order By, and Aliases in SQL
Group By, Order By, and Aliases in SQLGroup By, Order By, and Aliases in SQL
Group By, Order By, and Aliases in SQLMSB Academy
 
Relational Database Design
Relational Database DesignRelational Database Design
Relational Database DesignArchit Saxena
 

What's hot (20)

DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
 
Database abstraction
Database abstractionDatabase abstraction
Database abstraction
 
Key and its different types
Key and its different typesKey and its different types
Key and its different types
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
Types of keys in dbms
Types of keys in dbmsTypes of keys in dbms
Types of keys in dbms
 
Joins And Its Types
Joins And Its TypesJoins And Its Types
Joins And Its Types
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational model
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
 
SQL commands
SQL commandsSQL commands
SQL commands
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model Introduction
 
All data models in dbms
All data models in dbmsAll data models in dbms
All data models in dbms
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
ER-Model-ER Diagram
ER-Model-ER DiagramER-Model-ER Diagram
ER-Model-ER Diagram
 
Create table
Create tableCreate table
Create table
 
Dbms architecture
Dbms architectureDbms architecture
Dbms architecture
 
Er model ppt
Er model pptEr model ppt
Er model ppt
 
SQL Joins.pptx
SQL Joins.pptxSQL Joins.pptx
SQL Joins.pptx
 
Group By, Order By, and Aliases in SQL
Group By, Order By, and Aliases in SQLGroup By, Order By, and Aliases in SQL
Group By, Order By, and Aliases in SQL
 
Relational Database Design
Relational Database DesignRelational Database Design
Relational Database Design
 

Similar to Types of Keys in Database

Keys.pptx
Keys.pptxKeys.pptx
Keys.pptxrevathi s
 
DBMS key topic Presentation slide 1.pptx
DBMS key topic Presentation slide 1.pptxDBMS key topic Presentation slide 1.pptx
DBMS key topic Presentation slide 1.pptxsonudhakad173
 
Types of keys dbms
Types of keys dbmsTypes of keys dbms
Types of keys dbmsSurkhab Shelly
 
Types of keys in database | SQL
Types of keys in database | SQLTypes of keys in database | SQL
Types of keys in database | SQLSumit Pandey
 
Key in DatabaseManagementSystem_engineering.pptx
Key in DatabaseManagementSystem_engineering.pptxKey in DatabaseManagementSystem_engineering.pptx
Key in DatabaseManagementSystem_engineering.pptxsnehavenkatt27
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database ModelShishir Aryal
 
DBMS-Keys , Attributes and Constraints.pptx
DBMS-Keys , Attributes and Constraints.pptxDBMS-Keys , Attributes and Constraints.pptx
DBMS-Keys , Attributes and Constraints.pptxsajinis5
 
DBMS Keys.pptx
DBMS Keys.pptxDBMS Keys.pptx
DBMS Keys.pptxAryanGour1
 
2.2 keys
2.2 keys2.2 keys
2.2 keysELIMENG
 
Databases - Unit 2.pdf
Databases - Unit 2.pdfDatabases - Unit 2.pdf
Databases - Unit 2.pdfCynthiaAdzornu
 
Keys in Database
Keys in DatabaseKeys in Database
Keys in DatabaseA. S. M. Shafi
 
Chapter-5 The Relational Data Model
Chapter-5 The Relational Data ModelChapter-5 The Relational Data Model
Chapter-5 The Relational Data ModelKunal Anand
 

Similar to Types of Keys in Database (20)

Dbms keysppt
Dbms keyspptDbms keysppt
Dbms keysppt
 
Dbms keys
Dbms keysDbms keys
Dbms keys
 
Keys.pptx
Keys.pptxKeys.pptx
Keys.pptx
 
DBMS key topic Presentation slide 1.pptx
DBMS key topic Presentation slide 1.pptxDBMS key topic Presentation slide 1.pptx
DBMS key topic Presentation slide 1.pptx
 
Types of keys dbms
Types of keys dbmsTypes of keys dbms
Types of keys dbms
 
Types of keys in database | SQL
Types of keys in database | SQLTypes of keys in database | SQL
Types of keys in database | SQL
 
B & c
B & cB & c
B & c
 
Key in DatabaseManagementSystem_engineering.pptx
Key in DatabaseManagementSystem_engineering.pptxKey in DatabaseManagementSystem_engineering.pptx
Key in DatabaseManagementSystem_engineering.pptx
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database Model
 
DBMS_Keys.pdf
DBMS_Keys.pdfDBMS_Keys.pdf
DBMS_Keys.pdf
 
SQL_DBMS_KEYS.pptx
SQL_DBMS_KEYS.pptxSQL_DBMS_KEYS.pptx
SQL_DBMS_KEYS.pptx
 
DBMS-Keys , Attributes and Constraints.pptx
DBMS-Keys , Attributes and Constraints.pptxDBMS-Keys , Attributes and Constraints.pptx
DBMS-Keys , Attributes and Constraints.pptx
 
DBMS Keys.pptx
DBMS Keys.pptxDBMS Keys.pptx
DBMS Keys.pptx
 
2.2 keys
2.2 keys2.2 keys
2.2 keys
 
DBMS
DBMSDBMS
DBMS
 
DBMS:Relational Modal
DBMS:Relational ModalDBMS:Relational Modal
DBMS:Relational Modal
 
Databases - Unit 2.pdf
Databases - Unit 2.pdfDatabases - Unit 2.pdf
Databases - Unit 2.pdf
 
Keys in Database
Keys in DatabaseKeys in Database
Keys in Database
 
Keys used in database
Keys used in databaseKeys used in database
Keys used in database
 
Chapter-5 The Relational Data Model
Chapter-5 The Relational Data ModelChapter-5 The Relational Data Model
Chapter-5 The Relational Data Model
 

More from PadamNepal1

SHRM ( Strategic Human Resource Management)
SHRM ( Strategic Human Resource Management)SHRM ( Strategic Human Resource Management)
SHRM ( Strategic Human Resource Management)PadamNepal1
 
machinery of government.pptx
machinery of government.pptxmachinery of government.pptx
machinery of government.pptxPadamNepal1
 
Social development notes.pdf
Social development notes.pdfSocial development notes.pdf
Social development notes.pdfPadamNepal1
 
Social change,full notes
Social change,full notesSocial change,full notes
Social change,full notesPadamNepal1
 
legal provision for environment in Nepal
legal provision for environment in Nepallegal provision for environment in Nepal
legal provision for environment in NepalPadamNepal1
 
Store accounting
Store accountingStore accounting
Store accountingPadamNepal1
 
Project managemen PERT VS CPM
Project managemen  PERT VS CPMProject managemen  PERT VS CPM
Project managemen PERT VS CPMPadamNepal1
 

More from PadamNepal1 (7)

SHRM ( Strategic Human Resource Management)
SHRM ( Strategic Human Resource Management)SHRM ( Strategic Human Resource Management)
SHRM ( Strategic Human Resource Management)
 
machinery of government.pptx
machinery of government.pptxmachinery of government.pptx
machinery of government.pptx
 
Social development notes.pdf
Social development notes.pdfSocial development notes.pdf
Social development notes.pdf
 
Social change,full notes
Social change,full notesSocial change,full notes
Social change,full notes
 
legal provision for environment in Nepal
legal provision for environment in Nepallegal provision for environment in Nepal
legal provision for environment in Nepal
 
Store accounting
Store accountingStore accounting
Store accounting
 
Project managemen PERT VS CPM
Project managemen  PERT VS CPMProject managemen  PERT VS CPM
Project managemen PERT VS CPM
 

Recently uploaded

Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 

Recently uploaded (20)

Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 

Types of Keys in Database

  • 1. “TRIBHUVAN UNIVERSITY” DEPARTMENT OF PUBLIC ADMINISTRATION PUBLIC ADMINISTRATION CAMPUS PRESENTATION DIFFERENT TYPES OF KEYS IN DATABASE SUBMITED BY: PADAM NEPAL 029/074 6TH SEM
  • 2. 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
  • 3. 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 29/074 PADAM NEPAL COMPUTER 10/074 JANAK BHANDARI COMPUTER
  • 5. Super key in DBMS • A super key is a set of one or more attributes (columns), which can uniquely identify a row in a table. • A Super key for an entity is a set of one or more attributes whose combined value uniquely identifies the entity in the entity set. • A super key is a combine form of Primary Key, Alternate key and Unique key and Primary Key, Unique Key and Alternate Key are subset of super key. • A Super Key is simply a non-minimal Candidate Key, that is to say one with additional columns not strictly required to ensure uniqueness of the row. A super key can have a single column.
  • 6. example • Example: Super Keys in college_Info Table. • university_Id • college_Name • college_Code • { university_Id, college_Code } • { college_Name , college_Code } Super Keys in Student_Information Table: • Student_Id • College_Id • stu_Roll_No • { Student_Id, Student_Name} • { College_Id, Branch_Id } • { stu_Roll_No, Session }
  • 7. Candidate Key • A Candidate key is an attribute or set of attributes that uniquely identifies a record. Among the set of candidate, one candidate key is chosen as Primary Key. So a table can have multiple candidate key but each table can have maximum one primary key. • a candidate key is a minimal super key with no redundant attributes. Example: Possible Candidate Keys in college_Info table. • university_Id • college_Name • college_Code • Possible Candidate keys in Student_Information table. • Student_Id • College_Id • stu_Rollno
  • 8. Properties of Candidate key • It must contain unique values • Candidate key may have multiple attributes • Must not contain null values • It should contain minimum fields to ensure uniqueness • Uniquely identify each record in a table
  • 9. How candidate key is different from super key? • Candidate keys are selected from the set of super keys, the only thing we take care while selecting candidate key is: It should not have any redundant attribute. That’s the reason they are also termed as minimal super key. • all the candidate keys are super keys. This is because the candidate keys are chosen out of the super keys.
  • 10. Primary Key • A Primary key uniquely identifies each record in a table and must never be the same for the 2 records. • Primary key is a set of one or more fields ( columns) of a table that uniquely identify a record in database table. • A table can have only one primary key and one candidate key can select as a primary key. • The primary key should be chosen such that its attributes are never or rarely changed, for example, we can’t select Student_Id field as a primary key because in some case Student_Id of student may be changed
  • 11. Primary key examples • Primary Key in college_Info table: • university_Id • Primary Key in Student_Information Table: • College_Id
  • 12. Rules for defining Primary key: • Two rows can't have the same primary key value • It must for every row to have a primary key value. • The primary key field cannot be null. • The value in a primary key column can never be modified or updated if any foreign key refers to that primary key.
  • 13. What is the Alternate key? • 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
  • 14. 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
  • 15. 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 }
  • 16. 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.
  • 17. Cont. • Practically, the foreign key has nothing to do with the primary key tag of another table, if it points to a unique column (not necessarily a primary key) of another table then too, it would be a foreign key. So, a correct definition of foreign key would be: Foreign keys are the columns of a table that points to the candidate key of another table.
  • 18. Natural Keys: A natural key is a key composed of columns that actually have a logical relationship to other columns within a table. For example, if we use Student_Id, Student_Name and Father_Name columns to form a key then it would be “Natural Key” because there is definitely a relationship between these columns and other columns that exist in table. Natural keys are often called “Business Key ” or “Domain Key”.
  • 19. Surrogate Key: • Surrogate key is an artificial key that is used to uniquely identify the record in table. For example, in SQL Server or Sybase database system contain an artificial key that is known as “Identity”. Surrogate keys are just simple sequential number. Surrogate keys are only used to act as a primary key.
  • 20. Conclusion • Database generally only contain Primary Key, Foreign Key, Unique Key and Surrogate key and other remaining keys are just concept. A table must have a unique key. According to Dr. E. F. Codd ‘s third rule “Every single data element (value) is guaranteed to be accessible logically with a combination of table-name, primary-key (row value), and attribute-name (column value)”. So each table must have keys , because use of keys make data highly reliable and provide several types of content like unique data and null values.