0% found this document useful (0 votes)
18 views44 pages

DBMS - KCS501 - Notes Unit-1

DBMS notes semV

Uploaded by

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

DBMS - KCS501 - Notes Unit-1

DBMS notes semV

Uploaded by

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

 What are keys?

 Why we need keys in DBMS?


 Types of keys
What are Keys in
DBMS?
KEYS in DBMS is an
attribute or set of attributes
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.

For example: In Student table, ID is used as a key because it is unique for


each student. In PERSON table, passport_number, license_number, SSN
are keys since they are unique for each person.
Why we need Keys in DBMS
Example: Student Record
Sid Sname Sbranch Semail
1 John C.S [email protected]
2 Alice C.S. [email protected]
3 Alice I.T [email protected]
4 Eva E.C. [email protected]

For identifying any row of data in a table uniquely.

We can force identity of data and ensure integrity of data is


maintained.

To establish & identifying relationship between tables.


Types Of Keys

Some other keys are :-


Composite & Compound keys
Alternate keys
Surrogate keys
1. Primary key

It is the first key which is used to identify


one and only one instance of an entity
uniquely.

An entity can contain multiple keys as we


saw in PERSON table.

The key which is most suitable from those


lists become a primary key.

In the EMPLOYEE table, ID can be


primary key since it is unique for each
employee.
In the EMPLOYEE table, we can even select License_Number and
Passport_Number as primary key since they are also unique.
NOTE: For each entity, selection of the primary key is based on requirement
and developers.
Rules for defining Primary key:

Two rows can't have the same primary key value.

It is 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.
2. Super Key

Super key is a set of an attribute which can


uniquely identify a tuple.

Super key is a superset of a candidate key.

For example: In the EMPLOYEE table,


for(EMPLOEE_ID, EMPLOYEE_NAME)
the name of two employees can be the same,
but their EMPLYEE_ID can't be the same.
Hence, this combination can also be a key.

The super key would be EMPLOYEE-ID,


(EMPLOYEE_ID, EMPLOYEE-NAME),
etc.
3. Candidate key

Minimal subset of superkey.

A candidate key is an attribute or set of


an attribute which can uniquely identify a
tuple.

The remaining attributes except for


primary key are considered as a candidate
key.

 The candidate keys are as strong as the


primary key.

For example: In the EMPLOYEE table, id


is best suited for the primary key. Rest of
the attributes like SSN, Passport_Number,
and License_Number, etc. are considered
as a candidate key.
Rules for defining 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


4. Foreign key

Foreign keys are the column of


the table which is used to point
to the primary key of another
table.
In a company, every employee
works in a specific department,
and employee and department
are two different entities. So
we can't store the information
of the department in the
employee table.
That's why we link these two tables through the primary key of one table.
We add the primary key of the DEPARTMENT table, Department_Id as a
new attribute in the EMPLOYEE table.

Now in the EMPLOYEE table, Department_Id is the foreign key, and both
the tables are related.
Difference Between Primary key & Foreign key
Primary Key Foreign Key

Helps you to uniquely identify a record in the table. It is a field in the table that is the primary key of another
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 DBMS A foreign key cannot automatically create an index,
table are physically organized in the sequence of the clustered or non-clustered. However, you can manually
clustered index. create an index on the foreign key.

You can have the single Primary key in a table. You can have multiple foreign keys in a table.
5. Composite key

Any key with more than one attribute is called Composite key.

6. Compound key

If a Composite key has at -least one attribute that is a foreign key, then it is
called a compound key.

7. Surrogate Key

If a relation has no attribute which can be used to identify the data stored
in it, then we create an attribute for this purpose.

It adds no meaning to the data but serves the sole purpose of identifying
rows uniquely in the table.
 What is EER?
 Super class or subclass.
 Generalization
 Specialization
 Aggregation
What is Extended ER Model?

EER is a high-level data model that incorporates the extensions


to the original ER model. Enhanced ERD are high level models
that represent the requirements and complexities of complex
database.

In addition to ER model concepts EE-R includes


Subclasses and Super classes.
Specialization and Generalization.
Aggregation.

These concepts are used to create EE-R diagrams.


Subclasses and Super class

Super class is an entity that


can be divided into further
subtype.
For example − consider Shape
superclass.

Super class shape has sub


groups: Triangle, Square and
Circle.
Sub classes are the group of
entities with some unique
attributes.
Sub class inherits the
properties and attributes from
super class.
Generalization Specialization Aggregation

Abstracting process of Introducing new Compiling information on


viewing set of objects as characteristics to an an object, thereby
single general class. existing class of objects to abstracting higher level
create a new class. object
Bottom up Top down

Generalization
(bottom-up)

Specialization
(top-down)

Aggregation

You might also like