DBMS-Note-3
DBMS-Note-3
In a DBMS, KEYS are attributes or sets of attributes that enable the identification of
a row or tuple within a relation or table. They establish connections between different
tables and assist in uniquely identifying a row by utilizing one or more columns in the
table.
1. Primary Key
This type of keys in DBMS refers to a column that uniquely identifies all the records
within that table. A table has one primary key only, and this key must not contain
repeated or duplicated values across its rows. Each value within the primary
key must be unique, with no repetitions allowed.
The Primary Key field shouldn’t be left NULL; the Primary Key column must
contain a value.
In that column, no two rows in the table may contain identical values.
If a foreign key in a DBMS refers to the primary Key, no value may be altered
or modified in this primary key column.
1. Uniqueness is the most crucial element while selecting this key in DBMS. It
means that this column’s value does not occur in any other table row.
2. The definition and values shouldn’t be altered. While altering a PK column
value would need updating all referenced rows in the child (related) table,
altering a PK’s columns would necessitate redefining all pertinent foreign
keys.
3. If a composite primary key is used, no single column or smaller group of
columns should be able to identify each individual uniquely.
4. Use as few columns as you can, and if you can, pick columns whose values
are simple to read and recall.
2. Candidate Key
Candidate keys play a vital role in upholding the integrity and consistency of a
database. The purpose of this key in DBMS is to guarantee each row’s uniqueness
and independent identification within a table. Additionally, candidate keys enforce
relationships between tables, ensuring data integrity and maintaining overall
database consistency.
The candidate keys Roll No., Stud ID, and Email in the table enable us to identify
each student record uniquely.
A primary key is a column that allows each A column that can uniquely identify
entry in a database to be identified only once. each record in a database is sometimes
It is selected as the primary key for the table referred to as a candidate key. It might
from the list of potential keys. be used as the primary key.
The primary key enforces entity integrity, Candidate keys are potential candidates
The primary key is chosen by the database A candidate key can be chosen from
designer or administrator. the set of candidate keys for a table.
3. Super Key
The collection of all keys enabling us to recognize every row in the table is a super
key. This type of key in DBMS specifies that all the table columns that may identify
the columns uniquely function as the super keys.
It is a key that serves as both a secondary key and a primary key in two
different tables.
At any given time, it combines two or more relations.
They serve as cross-references for the tables.
121 Science
213 English
513 Computer
In this Key in DBMS example, we have two tables: instructor and department at a
school. However, it is hard to distinguish which instructor is assigned to which
division.
We can link the two tables in this table by adding the Foreign Key in Deptcode to the
Teacher name.
Data in one table is connected to another through foreign keys. To develop a manner
of cross-referencing two columns, a foreign key column in one table links to the
column in another table with unique values.
5. Alternate Key
A key in DBMS might be selected as the main Key in a table in multiple ways. Any
key that has the potential to replace the primary key but is not yet the primary key is
considered an alternate key. It’s a prospective main key that hasn’t been selected
yet.
Alternate keys refer to all keys that are not main keys.
It’s a backup key.
It has two or more fields that allow it to recognize two or more records.
These criteria are reiterated.
StudID, Roll No., and Email serves as the main keys. However, because StudID is
the main key, Roll No. and Email is now the secondary key.
6. Compound Key
This key in DBMS contains two or more characteristics that recognise a specific
record exclusively. It’s conceivable that none of the columns in the database are
unique on their own. However, when paired with the additional column or columns,
the composite key combination becomes unique. Each record in the table is to be
uniquely identified using the database’s compound key.
OrderNo and ProductID cannot be the main key since they do not uniquely identify a
record. A compound key combining the Order ID and Product ID might be utilized to
identify each record uniquely.
Compound keys are always constructed from two or more other tables’ primary keys.
Both keys uniquely identify data in their respective tables, but both are required to do
so in the table utilizing the compound key.
Null
Key Definitio Unique Alterati
Valu Purpose Index Usage
Type n ness on
es
Data
Establish
consisten More
es a
Not cy, May Betwee flexible
Foreig relations Allo
Require relations create n for
n Key hip wed
d hip Index tables mainten
between
maintena ance.
tables.
nce.
Alternati
Backup May
Candid ve Not May Within
Require primary become
ate unique Allo create same
d key primary
Key keys that wed Index table
options. key.
could be
Null
Key Definitio Unique Alterati
Valu Purpose Index Usage
Type n ness on
es
primary
keys.
Combina
tion of
Concept May Concep
Super attributes Require Allo
ual, not create tual N/A
Key that d wed
enforced. Index use
uniquely
identify.
Combine
Specializ Create May be
d
Comp Not ed s Within complex
attributes Require
osite Allo unique Comp same , impact
used as a d
Key wed identific osite table perform
single
ation. Index ance.
key.
Artificial
Enhance
keys Create Generall
d data
Surrog assigned Not s Within y static,
Require privacy,
ate for Allo Uniqu same non-
d data
Key record wed e table changin
warehou
identific Index g.
sing.
ation.