You are on page 1of 25

DBMS UNIT 3

Prepared By:
Ms. Barkha Namdev
Keys

• A key is an attribute or set of attributes which helps us in


uniquely identifying the rows of a table. It also helps in
establishing relationship among tables.
• Key can be of the following types:
• Super Key
• Candidate Key
• Primary Key
• Alternate key
• Foreign Key
Super key
• A super key or simply key is a combination of all possible
attribute which can uniquely identify the rows(tuples) in a
table. This means that a superkey may have some extra
attribute which isn't necessary for uniquely identifying the
rows in the table.
• Example: In the given Student Table we can have the
following keys as the super key.
Example:
Roll_No Name Registration_No
.

1 PRIYA 852
1. {Roll_no}
2 TUSHAR 536
2. {Registration_no}
3. {Roll_no, Registration_no}, 3 ANUJ 224
4. {Roll_no, Name}
4 PRIYA 552
5. {Name, Registration_no}
6. {Roll_no, Name, Registration_no}

All the above keys are able to uniquely identify each row. So, each of these
keys is super key. Here you can see that by using Roll_no only, we can
uniquely identify the rows but if you are making a super key, then you will try
to find all the possible cases of keys that can be used to identify data
uniquely.
Candidate key

• A candidate key is a minimal super key or a super key


with no redundant attribute.
• It is called a minimal superkey because we select a
candidate key from a set of super key such that selected
candidate key is the minimum attribute required to
uniquely identify the table.
• It is selected from the set of the super key which means
that all candidate keys are super key. Candidate Keys are
not allowed to have NULL values.
Candidate key
• Example: In the above example, we had 6 super keys but
all of them cannot become a candidate key. Only those
super keys would become a candidate key which have no
redundant attributes.
• 1. {Roll_no}: This key doesn't have any redundant or
repeating attribute. So, it can be considered as a
candidate key.
• 2. {Registration_no}: This key also doesn't have any
repeating attribute. So, it can be considered as a
candidate key.
Candidate key
• 3. {Roll_no, Registration_no}: This key cannot be considered as a candidate
key because when we take the subset of this key we get two attributes i.e
Roll_no or Registration_no. Each of these attributes is the candidate key. So,
it is not a minimal super key. Hence, this key is not a candidate key.
• 4. {Roll_no, Name}: This key cannot be considered as a candidate key
because when we take the subset of this key we get two attributes i.e.
Roll_no or Name. Roll_no is a candidate key. So, it is not a minimal super
key. Hence, this key is not a candidate key.
• 5. {Name, Registration_no}: This key cannot be considered as a candidate
key because when we take the subset of this key we get two attributes i.e
Registration_no or Name. Registration_no is a candidate key. So, it is not a
minimal super key. Hence, this key is not a candidate key.
Candidate key
• 6. {Roll_no, Name, Registration_no}: This key cannot be
considered as a candidate key because when we take the
subset of this key we get three attributes i.e Roll_no,
Registration_no and Name. Two of these attributes i.e
Roll_no and Registration_no are the candidate key. So, it
is not a minimal superkey. Hence, this key is not a
candidate key.
• So, from the above discussion, we conclude that we can
have only 2 out of above 6 super keys as the candidate
key. i.e. (Roll_no) and(Registration_no).
Candidate key Candidate key

Roll_No Name Registration_No.

1 PRIYA 852

2 TUSHAR 536

3 ANUJ 224
Primary key
• The primary key is the minimal set of attributes which
uniquely identifies any row of a table.
• It is selected from a set of candidate keys. Any
candidate key can become a primary key. It depends
upon the requirements and is done by the Database
Administrator (DBA).
• The primary key cannot have a NULL value. It cannot
have a duplicate value.
• The values of primary key can never be changed i.e. no
udation is possible.
Primary key
• Example: In the above example, we saw that we have two
candidate keys i.e (Roll_no) and (Registration_no).

• From this set, we can select any key as the primary key
for our table. It depends upon our requirement. Here, if we
are talking about class then selecting ‘Roll_no’ as the
primary key is more logical instead of ‘Registrartion_no’.
Primary key Candidate key
Roll_No Name Registration_No.

1 PRIYA 852

2 TUSHAR 536

3 ANUJ 224
Alternate key
• All the candidate key which are not a primary key are
called an alternate key.

• Example: In the above example, since we have made


‘Roll_no’ as the Primary Key our Alternate Key would be
‘Registration_no’.
Alternate key
Foreign key
• In the relational databases, a foreign key is a field or a
column that is used to establish a link between two
tables.This is sometimes also called as a referencing key.

• In simple words you can say that, a foreign key in one


table used to point primary key in another table.

• The relationship between 2 tables matches the Primary


Key in one of the tables with a Foreign Key in the second
table.
Foreign key

• Example: If we have two tables of Student and Course


then we can establish a relationship between these two
tables using a foreign key. The ‘Course_id’ in the Student
table is the foreign key as it establishes the link between
the Student and Course Table. So, if we need to find the
information about any course opted by any student then
we can go the Course table using the foreign key.
Foreign key

• One thing that is to be noted


here is that the foreign key of
one table may or may not be
the primary key. But it should
be the primary key of another
table. In the above example,
Course_id is not a primary key
in the Student table but it is a
primary key in the Course
table.
Domain
Roll_Num Student_N Student_A Student_G
• A Domain is Defined as ber ame ge ender
the set of all unique values 0122 Harshita 18 Female

permitted for an attribute 0123 Kunal 20 Male

.The domain of database


attribute is the set of all
allowable values for that
attribute.
• For Example:
Roll_Nu Student_ Student_ Student_
For Example mber Name Age Gender

0122 Harshita 18 Female

0123 Kunal 20 Male

• A field for gender may have the domain {


male,female,other } where those three values are the only
permitted entries in that column.
• A Domain of Name is the set of all possible cases.
• A Domain of date is the set of all possible valid dates.
• A Domain of day-of week- is
{Monday,Tuesday.....Sunday).
Relation Schema
• A relation schema is used to describe a relation.
• relation is made by so many attribute suppose we have a
relation R the R is denoted by R (a1, a2, a3………….an).
• Here R is the name of relation and a1, a2, a3…an are
sets of attributes and each attributes take different value .
• The number of attributes in a relation is called a degree of
relation.
• For ex: Student ( roll number, name , class , age ,
address)
• Here the degree of relation is 5.
Degree of Relationships

• Unary Relationship (Recursive Relationship): It is a


relationship between the instruction of single entity type ,
it is also called recursive relationship . this means in this
relationship entity related to itself.
• For ex: Person is an entity which is married to another
person.
• Employee is an entity which manage to so many
employees
Degree of Relationships

• Binary Relationship : It’s a relationship between the


instantaneous of two entity type , this means it connects
to 2 entity . In data modeling this relationship is a very
common relationship .
• For ex: Students take so many subject .
• Employee works on so many project.
Degree of Relationships

• Ternary Relationship: A ternary relationship is a


relationship between the instance of 3 entity types that is
in this relationship 3 entities are connect and this
relationship is a simultaneous relationship.
• for ex: In school has so many student & so many teacher
and this teacher teaches so many student.
• In a company has so many department & manager and
each department has so many managers.
What is a relational database?

• A relational database is a collection of information that


organizes data in predefined relationships where data is
stored in one or more tables (or "relations") of columns
and rows, making it easy to see and understand how
different data structures relate to each other.
• A relational database (RDB) is a way of structuring
information in tables, rows, and columns. An RDB has
the ability to establish links—or relationships–between
information by joining tables.
DIFFERENCE BETWEEN DBMS & RDBMS
DBMS RDMS

DBMS stores data as file. RDBMS stores data in tabular form.

No relationship between data. Data is stored in the form of tables which are
related to each other.

It deals with small quantity of data. It deals with large amount of data.

Data redundancy is common in this model. Keys and indexes do not allow Data
redundancy.
Normalization is not present. Normalization is present.

Low software and hardware necessities. Higher software and hardware necessities.

Data fetching is slower for the large amount of Data fetching is fast because of relational
data. approach.
Examples: XML, Window Registry, etc. Examples: MySQL, PostgreSQL, SQL Server,
Oracle, Microsoft Access etc.

You might also like