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

Key Constraint

This document outlines a lecture plan for a Database Management Systems course. It will cover the topic of keys in a DBMS. The lecture defines several types of keys including primary keys, foreign keys, candidate keys, surrogate keys and their properties and differences. It provides examples to illustrate each key type. It also lists questions for students about the differences between primary and unique keys, explaining different keys and integrity constraints, and when to use different types of primary keys. References for further reading are included.

Uploaded by

Vikram Nikhil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
147 views

Key Constraint

This document outlines a lecture plan for a Database Management Systems course. It will cover the topic of keys in a DBMS. The lecture defines several types of keys including primary keys, foreign keys, candidate keys, surrogate keys and their properties and differences. It provides examples to illustrate each key type. It also lists questions for students about the differences between primary and unique keys, explaining different keys and integrity constraints, and when to use different types of primary keys. References for further reading are included.

Uploaded by

Vikram Nikhil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

LECTURER PLAN FOR THE ACADEMIC YEAR(2019-2020)

NAME OF THE INSTITUTION: Stani Memorial College of Engineering & Technology, Phagi, Jaipur
BRANCH:CSE
SEMESTER/YEAR: IVth/IInd Year
SUBJECT: Database Management System
TEACH METHODOLOGY: Lecture Method/ O.H.P. / LCD/ Case Study/ Role Play/ Notes/ Any other
TOPIC: Key Constraint ` DATE: _____/_____/________
Lecture No. ____

1. INTRODUCTION

A DBMS key is an attribute or set of an attribute 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.

2. IMPORTANT EXPLAINATION / THEORY

Various Keys in Database Management System

DBMS has folwing seven types of Keys each have their different functionality:

 Super Key
 Primary Key
 Candidate Key
 Alternate Key
 Foreign Key
 Compound Key
 Composite Key
 Surrogate Key

Super key

A superkey is a group of single or multiple keys which identifies rows in a table. A Super key may have
additional attributes that are not needed for unique identification.

Example:

EmpSSN EmpNum Empname

9812345098 AB05 Shown

9876512345 AB06 Roslyn

199937890 AB07 James

In the above-given example, EmpSSN and EmpNum name are superkeys.


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:

In the following example, StudID is a Primary Key.

StudID Roll No First Name LastName Email

1 11 Tom Price [email protected]

2 12 Nick Wright [email protected]

3 13 Dana Natan [email protected]

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.

Example: In this table.

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 Tom Price [email protected]

2 12 Nick Wright [email protected]

3 13 Dana Natan [email protected]

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

Example: In the given table Stud ID, Roll No, and email are candidate keys which help us to uniquely identify
the student record in the table.

StudID Roll No First Name LastName Email

1 11 Tom Price [email protected]

2 12 Nick Wright [email protected]

3 13 Dana Natan [email protected]

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.

Example:

DeptCode DeptName

001 Science

002 English

005 Computer

Teacher ID Fname Lname


B002 David Warner

B017 Sara Joseph

B009 Mike Brunton

In this example, we have two table, teach and department in a school. However, there is no way to see which
search work in which department.

In this table, adding the foreign key in Deptcode to the Teacher name, we can create a relationship between
the two tables.

Teacher ID DeptCode Fname Lname

B002 002 David Warner

B017 002 Sara Joseph

B009 001 Mike Brunton

This concept is also known as Referential Integrity.

Compound key

Compound key has many fields which allow you to uniquely recognize a specific record. It is possible that
each column may be not unique by itself within the database. However, when combined with the other column
or columns the combination of composite keys become unique.

Example:

OrderNo PorductID Product Name Quantity

B005 JAP102459 Mouse 5

B005 DKT321573 USB 10

B005 OMG446789 LCD Monitor 20

B004 DKT321573 USB 15

B002 OMG446789 Laser Printer 3

In this example, OrderNo and ProductID can't be a primary key as it does not uniquely identify a record.
However, a compound key of Order ID and Product ID could be used as it uniquely identified each record.
Composite key

A key which has multiple attributes to uniquely identify rows in a table is called a composite key. The
difference between compound and the composite key is that any part of the compound key can be a foreign
key, but the composite key may or maybe not a part of the foreign key.

Surrogate Key

An artificial key which aims to uniquely identify each record is called a surrogate key. These kind of key are
unique because they are created when you don't have any natural primary key. They do not lend any meaning
to the data in the table. Surrogate key is usually an integer.

Fname Lastname Start Time End Time

Anne Smith 09:00 18:00

Jack Francis 08:00 17:00

Anna McLean 11:00 20:00

Shown Willam 14:00 23:00

Above, given example, shown shift timings of the different employee. In this example, a surrogate key is
needed to uniquely identify each employee.

Surrogate keys are allowed when

 No property has the parameter of the primary key.


 In the table when the primary key is too big or complicated.

Difference Between Primary key & Foreign key


Primary Key Foreign Key

Helps you to uniquely identify a record in the It is a field in the table that is the primary key of another
table. table.

Primary Key never accept null values. A foreign key may accept multiple null values.

Primary key is a clustered index and data in the A foreign key cannot automatically create an index,
DBMS table are physically organized in the clustered or non-clustered. However, you can manually
sequence of the clustered index. create an index on the foreign key.

You can have the single Primary key in a table.


3. CONCERNED UNIVERSITY QUESTIONS

Q1 What is the Difference between primary key and unique key?


Q2 Explain different keys and integrity constraints available in DBMS.
Q3 Explain when to use primary keys, composite primary keys and surrogate primary keys

4. REFERENCES

BOOK : 1) Database Management Systems By Raghu Ramakrishnan


2) Fundamentals of Database System By Navathe
3) Database System Concepts By Korth and Sudarshan
4) Fundamentals of Database System By P. K. Sinha

INTERNET : https://www.javatpoint.com
https://www.tutorialspoint.com

NAME OF FACULTY : ONAM JAIN

SIGNATURE : ___________________________________________

VERIFIED BY HOD : ___________________________________________

You might also like