0% found this document useful (0 votes)
78 views

Keys in Database: By-Suraj Dewasi Prachi Singh Rathore

The document discusses different types of keys used in database management. It defines a key as a column or set of columns that uniquely identifies each record in a table. The main types of keys discussed are primary keys, alternate keys, candidate keys, foreign keys, and super keys. It provides examples to illustrate each key type and how they can be used to identify records, enforce data integrity, and define relationships between database tables.

Uploaded by

Suraj Dewasi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views

Keys in Database: By-Suraj Dewasi Prachi Singh Rathore

The document discusses different types of keys used in database management. It defines a key as a column or set of columns that uniquely identifies each record in a table. The main types of keys discussed are primary keys, alternate keys, candidate keys, foreign keys, and super keys. It provides examples to illustrate each key type and how they can be used to identify records, enforce data integrity, and define relationships between database tables.

Uploaded by

Suraj Dewasi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

KEYS IN DATABASE

BY- SURAJ DEWASI


PRACHI SINGH RATHORE
INTRODUCTION
A Key is a data item that exclusively identifies a
record. In other words, key is a set of column(s)
that is used to uniquely identify the record in a
table. It is used to fetch or retrieve records /
data-rows from data table according to the
condition/requirement. Key provide several
types of constraints like column can’t store
duplicate values or null values. Keys are also
used to generate relationship among different
database tables or views.
• Keys are the essential elements of any
relational database.It identifies each tuple in a
relation uniquely.Keys are also used to
establish the relationship among the tables in
a schema
TYPES OF KEYS
• Super Key
• Minimal Super Key
• Candidate Key
• Primary Key
• Unique Key
• Alternate Key
• Composite Key
• Foreign Key
• Surrogate Key
PRIMARY KEY
• What is a Primary Key?
• A column or group of columns in a table which helps us to
uniquely identifies every row in that table is called a primary key.
This DBMS can't be a duplicate. The same value can't appear
more than once in the table.

• 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.
EXAMPLE
StudID Roll No First Name LastName Email

1 11 ELEVEN HOPPER [email protected]


m

2 12 MIKE WHEELAR [email protected]


m

3 13 NANCY WHEELAR [email protected]


om
ALTERNATE KEY
• What is the Alternate key?
• All the keys which are not primary key are
called an alternate key. It is a candidate key
which is currently not the primary key.
However, A table may have single or multiple
choices for the primary key.
StudID, Roll No, Email are qualified to become a
primary key. But since StudID is the primary key,
Roll No, Email becomes the alternative key

StudID Roll No First Name LastName Email


1 11 Dustin Price abc@gmail.
com
2 12 Lucas Wright [email protected]
om
3 13 Maxine Natan mno@yaho
o.com
CANDIDATE KEY

• A super key with no repeated attribute is called


candidate key.
• The Primary key should be selected from the candidate
keys. Every table must have at least a single candidate
key.
• 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
StudID Roll No First Name LastName Email
1 11 Tom Price abc@gmail.
com
2 12 Nick Wright [email protected]
om
3 13 Dana Natan mno@yaho
o.com
FOREIGN KEY
• A foreign key is a column which is
added to create a relationship with
another table. Foreign keys help us to
maintain data integrity and also
allows navigation between two
different instances of an entity. Every
relationship in the model needs to be
supported by a foreign key.
STUDENT COLLEGE STUDENT ROLL FATHER SESSION ADDRESS BRANCH
ID ID NAME NUMBER NAME ID
1 1231 JANE 1111 HOPPER
2 1232 MIKE 1108 WEELAR
3 1233 NANCY 4567 WEELAR
4 1234 STEVE 2344 HERRIN
5 1235 LUCAS 6475 MNOP
6 1236 DUSTIN 4536 RTYU
7 1237 WILL 6537 BYER
8 1238 BILLY 1426 LIMS
SUPER KEY
• A single attribute or a set of attributes that can
uniquely identify all attributes of a particular
relation is called Super key.A
• Super Key can contains one or more than one
attributes.
• A Super Key is the most general type of key
• The combination of “Cust_ID” and “Name” is a
super key of the following entity set customer.
Because:
The value of attributes “Cust_ID” and
“Name”, such as C101 and AHMAD can uniquely
identify that particular customer in customer
entity set, which is the pool of all
customers.

You might also like