SlideShare a Scribd company logo
1 of 13
Key
DBMS
Prepared By: Bikash Sapkota
Deerwalk Ins. Of Technology
Kathmandu, Nepal
Introduction
 Keys(Name clearly define)
A key part of a relational database and a vital part of the structure of
a table. They ensure each record within a table can be uniquely
identified by one or a combination of fields within the table. They help
enforce integrity and help identify the relationship between tables.
Keys
 Super Key
 Candidate Key
 Primary Key
Super Key
 A Super key is any combination of fields within a table that uniquely
identifies each record within that table.
Book
Book ID Name Author
B1 Xyz A1
B2 ABC A1
B3 XYZ A2
B4 PQR A3
B5 RST A1
B6 ABC A3
Candidate Key
 Candidate key is a subset of super key
 A candidate key is a single field or the least combination of fields that
uniquely identifies each record in table
 The least combination of fields distinguishes a candidate key from a
super key.
 Every table must have at least one candidate
 Properties
 Unique
 Not null
 Contains minimum number of fields to ensure uniqueness
 Must uniquely identify each record in the table
Book ID Name Author
B1 XYZ A!
B2 ABC A1
B3 XYZ A2
B4 PQR A3
B5 RST A1
B6 ABC A3
Name BookId Author Name Author
Primary Key
 It is a candidate key
 Uniquely identify a specific instance of an entity
 Primary key cannot contain any Null value because we cannot
uniquely identify multiple Null values.
 Properties
 Stable
 Minimal
 Definitive
 Accessible
Book ID Name Author
B1 Xyz A!
B2 ABC A1
B3 XYZ A2
B4 PQR A3
B5 RST A1
B6 ABC A3
Book ID Name Author
 CREATE TABLE Persons
(
P_Id int NOT NULL PRIMARY KEY,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);
 CREATE TABLE Person
(
P_Id int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255),
CONSTRAINT pk_PersonID PRIMARY KEY (P_Id,LastName)
);
Foreign Key
 Foreign key is a field in a relational table that matches the primary
key column of another table.
 It can be used to link two tables together
 CREATE TABLE supplier
 ( supplier_id numeric(10) not null,
 supplier_name varchar2(50) not null,
 contact_name varchar2(50),
 CONSTRAINT supplier_pk PRIMARY KEY (supplier_id)
 );
 CREATE TABLE products
 ( product_id numeric(10) not null,
 supplier_id numeric(10) not null,
 CONSTRAINT fk_supplier
 FOREIGN KEY (supplier_id)
 REFERENCES supplier(supplier_id)
 );
Remaining
Alternate Key
Remaining candidate key which are not selected as primary key
Composite Key
Primary key made up of more than one attribute

More Related Content

Viewers also liked

Ekonomický týždenník Poštovej banky - 44. týždeň
Ekonomický týždenník Poštovej banky - 44. týždeňEkonomický týždenník Poštovej banky - 44. týždeň
Ekonomický týždenník Poštovej banky - 44. týždeňpabk
 
Ekonomický týždenník Poštovej banky - 32. týždeň
Ekonomický týždenník Poštovej banky - 32. týždeňEkonomický týždenník Poštovej banky - 32. týždeň
Ekonomický týždenník Poštovej banky - 32. týždeňpabk
 
От SIEM к SOC дорогу осилит смотрящий
От SIEM к SOC дорогу осилит смотрящийОт SIEM к SOC дорогу осилит смотрящий
От SIEM к SOC дорогу осилит смотрящийjet_information_security
 
Reflections on teachingand more (1)
Reflections on teachingand more (1)Reflections on teachingand more (1)
Reflections on teachingand more (1)Maureen Murphy
 
Ekonomický týždenník Poštovej banky - 27. týždeň
Ekonomický týždenník Poštovej banky - 27. týždeňEkonomický týždenník Poštovej banky - 27. týždeň
Ekonomický týždenník Poštovej banky - 27. týždeňpabk
 
Путешествие по Германии
Путешествие по ГерманииПутешествие по Германии
Путешествие по ГерманииMasha Senti
 
Stvorimo bolji internet zajedno rea i evelyn
Stvorimo bolji internet zajedno rea i evelynStvorimo bolji internet zajedno rea i evelyn
Stvorimo bolji internet zajedno rea i evelynNatasa_007
 
Ekonomický týždenník Poštovej banky - 39. týždeň
Ekonomický týždenník Poštovej banky - 39. týždeňEkonomický týždenník Poštovej banky - 39. týždeň
Ekonomický týždenník Poštovej banky - 39. týždeňpabk
 

Viewers also liked (13)

UX wireframes
UX wireframesUX wireframes
UX wireframes
 
Ekonomický týždenník Poštovej banky - 44. týždeň
Ekonomický týždenník Poštovej banky - 44. týždeňEkonomický týždenník Poštovej banky - 44. týždeň
Ekonomický týždenník Poštovej banky - 44. týždeň
 
Ekonomický týždenník Poštovej banky - 32. týždeň
Ekonomický týždenník Poštovej banky - 32. týždeňEkonomický týždenník Poštovej banky - 32. týždeň
Ekonomický týždenník Poštovej banky - 32. týždeň
 
10.hafta sunu
10.hafta sunu10.hafta sunu
10.hafta sunu
 
От SIEM к SOC дорогу осилит смотрящий
От SIEM к SOC дорогу осилит смотрящийОт SIEM к SOC дорогу осилит смотрящий
От SIEM к SOC дорогу осилит смотрящий
 
Reflections on teachingand more (1)
Reflections on teachingand more (1)Reflections on teachingand more (1)
Reflections on teachingand more (1)
 
Ekonomický týždenník Poštovej banky - 27. týždeň
Ekonomický týždenník Poštovej banky - 27. týždeňEkonomický týždenník Poštovej banky - 27. týždeň
Ekonomický týždenník Poštovej banky - 27. týždeň
 
Путешествие по Германии
Путешествие по ГерманииПутешествие по Германии
Путешествие по Германии
 
ИБ эпохи перемен
ИБ эпохи переменИБ эпохи перемен
ИБ эпохи перемен
 
TIK BAB 5
TIK BAB 5TIK BAB 5
TIK BAB 5
 
Can we share
Can we shareCan we share
Can we share
 
Stvorimo bolji internet zajedno rea i evelyn
Stvorimo bolji internet zajedno rea i evelynStvorimo bolji internet zajedno rea i evelyn
Stvorimo bolji internet zajedno rea i evelyn
 
Ekonomický týždenník Poštovej banky - 39. týždeň
Ekonomický týždenník Poštovej banky - 39. týždeňEkonomický týždenník Poštovej banky - 39. týždeň
Ekonomický týždenník Poštovej banky - 39. týždeň
 

Similar to Key

Types of keys in dbms
Types of keys in dbmsTypes of keys in dbms
Types of keys in dbmsdarshhingu
 
oracle Sql constraint
oracle  Sql constraint oracle  Sql constraint
oracle Sql constraint home
 
Relational database management system
Relational database management systemRelational database management system
Relational database management systemPraveen Soni
 
key (1).pptx
key (1).pptxkey (1).pptx
key (1).pptxKAnurag2
 
Sql practise for beginners
Sql practise for beginnersSql practise for beginners
Sql practise for beginnersISsoft
 
introdution concept on _ _ sql_basic.ppt
introdution concept on _ _ sql_basic.pptintrodution concept on _ _ sql_basic.ppt
introdution concept on _ _ sql_basic.pptriscomputersir
 
Relational Model - An Introduction
Relational Model - An IntroductionRelational Model - An Introduction
Relational Model - An IntroductionRajeev Srivastava
 
Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)SURBHI SAROHA
 
Sql ch 12 - creating database
Sql ch 12 - creating databaseSql ch 12 - creating database
Sql ch 12 - creating databaseMukesh Tekwani
 

Similar to Key (12)

Types of keys in dbms
Types of keys in dbmsTypes of keys in dbms
Types of keys in dbms
 
key.pptx
key.pptxkey.pptx
key.pptx
 
oracle Sql constraint
oracle  Sql constraint oracle  Sql constraint
oracle Sql constraint
 
Relational database management system
Relational database management systemRelational database management system
Relational database management system
 
Create table
Create tableCreate table
Create table
 
key (1).pptx
key (1).pptxkey (1).pptx
key (1).pptx
 
Sql practise for beginners
Sql practise for beginnersSql practise for beginners
Sql practise for beginners
 
introdution concept on _ _ sql_basic.ppt
introdution concept on _ _ sql_basic.pptintrodution concept on _ _ sql_basic.ppt
introdution concept on _ _ sql_basic.ppt
 
Relational Model - An Introduction
Relational Model - An IntroductionRelational Model - An Introduction
Relational Model - An Introduction
 
Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)Keys in dbms(UNIT 2)
Keys in dbms(UNIT 2)
 
Sql ch 12 - creating database
Sql ch 12 - creating databaseSql ch 12 - creating database
Sql ch 12 - creating database
 
Keys in Database
Keys in DatabaseKeys in Database
Keys in Database
 

Recently uploaded

Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 

Recently uploaded (20)

Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 

Key

  • 1. Key DBMS Prepared By: Bikash Sapkota Deerwalk Ins. Of Technology Kathmandu, Nepal
  • 2. Introduction  Keys(Name clearly define) A key part of a relational database and a vital part of the structure of a table. They ensure each record within a table can be uniquely identified by one or a combination of fields within the table. They help enforce integrity and help identify the relationship between tables.
  • 3. Keys  Super Key  Candidate Key  Primary Key
  • 4. Super Key  A Super key is any combination of fields within a table that uniquely identifies each record within that table.
  • 5. Book Book ID Name Author B1 Xyz A1 B2 ABC A1 B3 XYZ A2 B4 PQR A3 B5 RST A1 B6 ABC A3
  • 6. Candidate Key  Candidate key is a subset of super key  A candidate key is a single field or the least combination of fields that uniquely identifies each record in table  The least combination of fields distinguishes a candidate key from a super key.  Every table must have at least one candidate  Properties  Unique  Not null  Contains minimum number of fields to ensure uniqueness  Must uniquely identify each record in the table
  • 7. Book ID Name Author B1 XYZ A! B2 ABC A1 B3 XYZ A2 B4 PQR A3 B5 RST A1 B6 ABC A3 Name BookId Author Name Author
  • 8. Primary Key  It is a candidate key  Uniquely identify a specific instance of an entity  Primary key cannot contain any Null value because we cannot uniquely identify multiple Null values.  Properties  Stable  Minimal  Definitive  Accessible
  • 9. Book ID Name Author B1 Xyz A! B2 ABC A1 B3 XYZ A2 B4 PQR A3 B5 RST A1 B6 ABC A3 Book ID Name Author
  • 10.  CREATE TABLE Persons ( P_Id int NOT NULL PRIMARY KEY, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255) );  CREATE TABLE Person ( P_Id int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255), CONSTRAINT pk_PersonID PRIMARY KEY (P_Id,LastName) );
  • 11. Foreign Key  Foreign key is a field in a relational table that matches the primary key column of another table.  It can be used to link two tables together
  • 12.  CREATE TABLE supplier  ( supplier_id numeric(10) not null,  supplier_name varchar2(50) not null,  contact_name varchar2(50),  CONSTRAINT supplier_pk PRIMARY KEY (supplier_id)  );  CREATE TABLE products  ( product_id numeric(10) not null,  supplier_id numeric(10) not null,  CONSTRAINT fk_supplier  FOREIGN KEY (supplier_id)  REFERENCES supplier(supplier_id)  );
  • 13. Remaining Alternate Key Remaining candidate key which are not selected as primary key Composite Key Primary key made up of more than one attribute

Editor's Notes

  1. There are three main types of keys, candidate keys, primary keys and foreign keys. There is also an alternative key or secondary key that can be used, as the name suggests, as a secondary or alternative key to the primary key
  2. If 3 are super key then name and author are redundant key
  3. Cannot be reduced further