SlideShare a Scribd company logo
1 of 16
“TYPES OF KEYS IN
DATABASE”
PRESENTED BY:
DARSHAN HINGU
OBJECTIVES
 WHAT IS KEY?
 Super Key
 Primary Key
 Candidate Key
 Alternate Key
 Foreign Key
WHAT IS KEY?
 Keys are very important part of Relational database model.
 To maintain data integrity (that is data should be correct and in well
formed) we use concept of keys.
 It is used for identifying unique rows from table.
 They are used to establish and identify relationships between tables.
SUPER KEY
 A super key is any combination of columns within a table that uniquely identifies
each record within that table.
 As an example, a table used to store customer master details could contain
columns such as:
 Customer name
 Customer ID
 Social Security number (SSN)
 Address
 Date of birth
 A certain set of columns may be extracted and guaranteed unique to each
customer. Examples of super keys are as follows:
 Name+SSN+DOB
 ID+Name+SSN
 All keys are Super key but not vice versa.
PRIMARY KEY
 A primary key is a column in a table that uniquely identifies the rows in that
table.
 The data values placed in the primary key column must be unique to each
row; no duplicates can be used.
 Nulls are not allowed in primary key columns.
 For example, in the table below, CustomerNo, which displays the ID number
assigned to different customers, is the primary key.
 CREATE TABLE CUSTOMER
( CustomerNO int NOT NULL PRIMARY KEY,
FirstName varchar(20),
LastName varchar(20)
);
CustomerNo FirstName LastName
1 Sally Thompson
2 Sally Henderson
3 Harry Henderson
4 Sandra Wellington
CANDIDATE KEY
 There can be more than one candidate keys for a table.
 A candidate key of a relation is a minimal super key for that relation.
 A candidate key can be a combination of more than one columns.
 A Candidate Key is a set of one or more columns that can identify a
record uniquely in a table. There can be multiple Candidate Keys in one
table.
 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 attributes.
 A primary key is being selected from the group of candidate keys.
 The value of Candidate Key is non-null for every tuple.
ALTERNATE KEY
 Alternate keys are candidate keys that are not selected as primary key.
 Alternate key is also called “Secondary Key”.
 If any table have more than one candidate key, then after choosing
primary key from those candidate key, rest of candidate keys are known
as an alternate key of that table.
FOREIGN KEY
 Foreign key are those keys which is used to define relationship between
two tables.
 Foreign key are columns that point to primary key columns in other
database tables.
 It can accept multiple null, duplicate values.
 It is also known as referential integrity.
 --Course Table
CREATE TABLE course
(
courseid NUMBER(10) NOT NULL PRIMARY KEY, --primary key
CourseName varchar2(10) NOT NULL,
) ;
--Student Table
CREATE TABLE Student
(
studentId NUMBER(10) NOT NULL PRIMARY KEY, --primary key
firstName varchar2(10) NOT NULL,
lastName varchar2(10) NOT NULL,
courseid NUMBER(10) REFERENCES course(courseid) --foreign key
) ;
Example : We can have a courseid column in the Student table which is pointing to courseid
column in a course table where it a primary key.
RELATIONSHIP BETWEEN KEYS
THAN
KYOU

More Related Content

What's hot

What's hot (20)

Types Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql ServerTypes Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql Server
 
Advantages of DBMS
Advantages of DBMSAdvantages of DBMS
Advantages of DBMS
 
Er model ppt
Er model pptEr model ppt
Er model ppt
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database Model
 
Types of keys dbms
Types of keys dbmsTypes of keys dbms
Types of keys dbms
 
Bcnf
BcnfBcnf
Bcnf
 
Key and its different types
Key and its different typesKey and its different types
Key and its different types
 
Database Relationships
Database RelationshipsDatabase Relationships
Database Relationships
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
 
Joins And Its Types
Joins And Its TypesJoins And Its Types
Joins And Its Types
 
Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship Diagram
 
Relational keys
Relational keysRelational keys
Relational keys
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
Linked list
Linked listLinked list
Linked list
 
Data Structures : hashing (1)
Data Structures : hashing (1)Data Structures : hashing (1)
Data Structures : hashing (1)
 
Entity (types, attibute types)
Entity (types, attibute types)Entity (types, attibute types)
Entity (types, attibute types)
 
SQL Joins.pptx
SQL Joins.pptxSQL Joins.pptx
SQL Joins.pptx
 

Similar to Types of keys in dbms

Similar to Types of keys in dbms (20)

Keys in Database
Keys in DatabaseKeys in Database
Keys in Database
 
key (1).pptx
key (1).pptxkey (1).pptx
key (1).pptx
 
SQL_DBMS_KEYS.pptx
SQL_DBMS_KEYS.pptxSQL_DBMS_KEYS.pptx
SQL_DBMS_KEYS.pptx
 
Keys used in database
Keys used in databaseKeys used in database
Keys used in database
 
key.pptx
key.pptxkey.pptx
key.pptx
 
Dbms keysppt
Dbms keyspptDbms keysppt
Dbms keysppt
 
Types of keys in database | SQL
Types of keys in database | SQLTypes of keys in database | SQL
Types of keys in database | SQL
 
Keys.pptx
Keys.pptxKeys.pptx
Keys.pptx
 
computer-210809080138.pdf
computer-210809080138.pdfcomputer-210809080138.pdf
computer-210809080138.pdf
 
B & c
B & cB & c
B & c
 
Keys presentation
Keys presentationKeys presentation
Keys presentation
 
Doc 20191022-wa0041
Doc 20191022-wa0041Doc 20191022-wa0041
Doc 20191022-wa0041
 
2.2 keys
2.2 keys2.2 keys
2.2 keys
 
Intro to Data warehousing lecture 12
Intro to Data warehousing   lecture 12Intro to Data warehousing   lecture 12
Intro to Data warehousing lecture 12
 
Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)
 
Key in DatabaseManagementSystem_engineering.pptx
Key in DatabaseManagementSystem_engineering.pptxKey in DatabaseManagementSystem_engineering.pptx
Key in DatabaseManagementSystem_engineering.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
 
DBMS_Keys.pdf
DBMS_Keys.pdfDBMS_Keys.pdf
DBMS_Keys.pdf
 
Understanding Entity Relationship Models
Understanding Entity Relationship ModelsUnderstanding Entity Relationship Models
Understanding Entity Relationship Models
 
Whats the Schema Table Column Row Attribute Entity Pri.pdf
Whats the Schema  Table  Column  Row  Attribute  Entity  Pri.pdfWhats the Schema  Table  Column  Row  Attribute  Entity  Pri.pdf
Whats the Schema Table Column Row Attribute Entity Pri.pdf
 

Recently uploaded

What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 

Recently uploaded (20)

What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 

Types of keys in dbms

  • 1. “TYPES OF KEYS IN DATABASE” PRESENTED BY: DARSHAN HINGU
  • 2. OBJECTIVES  WHAT IS KEY?  Super Key  Primary Key  Candidate Key  Alternate Key  Foreign Key
  • 3. WHAT IS KEY?  Keys are very important part of Relational database model.  To maintain data integrity (that is data should be correct and in well formed) we use concept of keys.  It is used for identifying unique rows from table.  They are used to establish and identify relationships between tables.
  • 4. SUPER KEY  A super key is any combination of columns within a table that uniquely identifies each record within that table.  As an example, a table used to store customer master details could contain columns such as:  Customer name  Customer ID  Social Security number (SSN)  Address  Date of birth
  • 5.  A certain set of columns may be extracted and guaranteed unique to each customer. Examples of super keys are as follows:  Name+SSN+DOB  ID+Name+SSN  All keys are Super key but not vice versa.
  • 6. PRIMARY KEY  A primary key is a column in a table that uniquely identifies the rows in that table.  The data values placed in the primary key column must be unique to each row; no duplicates can be used.  Nulls are not allowed in primary key columns.  For example, in the table below, CustomerNo, which displays the ID number assigned to different customers, is the primary key.
  • 7.  CREATE TABLE CUSTOMER ( CustomerNO int NOT NULL PRIMARY KEY, FirstName varchar(20), LastName varchar(20) ); CustomerNo FirstName LastName 1 Sally Thompson 2 Sally Henderson 3 Harry Henderson 4 Sandra Wellington
  • 8. CANDIDATE KEY  There can be more than one candidate keys for a table.  A candidate key of a relation is a minimal super key for that relation.  A candidate key can be a combination of more than one columns.  A Candidate Key is a set of one or more columns that can identify a record uniquely in a table. There can be multiple Candidate Keys in one table.  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 attributes.
  • 9.  A primary key is being selected from the group of candidate keys.  The value of Candidate Key is non-null for every tuple.
  • 10. ALTERNATE KEY  Alternate keys are candidate keys that are not selected as primary key.  Alternate key is also called “Secondary Key”.  If any table have more than one candidate key, then after choosing primary key from those candidate key, rest of candidate keys are known as an alternate key of that table.
  • 11. FOREIGN KEY  Foreign key are those keys which is used to define relationship between two tables.  Foreign key are columns that point to primary key columns in other database tables.  It can accept multiple null, duplicate values.  It is also known as referential integrity.
  • 12.  --Course Table CREATE TABLE course ( courseid NUMBER(10) NOT NULL PRIMARY KEY, --primary key CourseName varchar2(10) NOT NULL, ) ; --Student Table CREATE TABLE Student ( studentId NUMBER(10) NOT NULL PRIMARY KEY, --primary key firstName varchar2(10) NOT NULL, lastName varchar2(10) NOT NULL, courseid NUMBER(10) REFERENCES course(courseid) --foreign key ) ; Example : We can have a courseid column in the Student table which is pointing to courseid column in a course table where it a primary key.
  • 13.
  • 15.