0% found this document useful (0 votes)
2 views26 pages

dbms 2

The document provides an overview of the Relational Data Model in Database Management Systems (DBMS), explaining key concepts such as relations, attributes, and integrity constraints. It details various types of keys, including primary, foreign, and candidate keys, and discusses operations like insert, update, delete, and select. Additionally, it highlights best practices, advantages, and disadvantages of using the relational model, as well as the normalization process to ensure data consistency and eliminate redundancy.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views26 pages

dbms 2

The document provides an overview of the Relational Data Model in Database Management Systems (DBMS), explaining key concepts such as relations, attributes, and integrity constraints. It details various types of keys, including primary, foreign, and candidate keys, and discusses operations like insert, update, delete, and select. Additionally, it highlights best practices, advantages, and disadvantages of using the relational model, as well as the normalization process to ensure data consistency and eliminate redundancy.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Relational Data Model in DBMS:

Concepts, Constraints, Example


What is Relational Model?
Relational Model (RM) represents the database as a
collection of relations. A relation is nothing but a table of
values. Every row in the table represents a

collection of related data values. These rows in the table


denote a real-world entity or relationship.

The table name and column names are helpful to interpret


the meaning of values in each row. The data are
represented as a set of relations. In the relational model,
data are stored as tables. However, the physical storage of
the data is independent of the way the data are logically
organized.

Some popular Relational Database management systems are:

• DB2 and Informix Dynamic Server - IBM


• Oracle and RDB – Oracle
• SQL Server and Access - Microsoft

In this tutorial, you will learn

• Relational Model Concepts


• Relational Integrity Constraints
• Operations in Relational Model
• Best Practices for creating a Relational Model
• Advantages of using Relational Model  Disadvantages of
using Relational Model

Relational Model Concepts


1. Attribute: Each column in a Table. Attributes are the
properties which define a relation. e.g.,
Student_Rollno, NAME,etc.
2. Tables – In the Relational model the, relations are
saved in the table format. It is stored along with its
entities. A table has two properties rows and columns.
Rows represent records and columns represent
attributes.
3. Tuple – It is nothing but a single row of a table, which
contains a single record.
4. Relation Schema: A relation schema represents the
name of the relation with its attributes.
5. Degree: The total number of attributes which in the
relation is called the degree of the relation.
6. Cardinality: Total number of rows present in the
Table.
7. Column: The column represents the set of values for
a specific attribute.
8. Relation instance – Relation instance is a finite set of
tuples in the RDBMS system. Relation instances
never have duplicate tuples.
9. Relation key - Every row has one, two or multiple
attributes, which is called relation key.
10. Attribute domain – Every attribute has some pre-
defined value and scope which is known as attribute
domain

Relational Integrity Constraints


Relational Integrity constraints in DBMS are referred to
conditions which must be present for a valid relation. These
Relational constraints in DBMS are derived from the rules in
the mini-world that the database represents.

There are many types of Integrity Constraints in DBMS.


Constraints on the Relational database management
system is mostly divided into three main categories are:
1. Domain Constraints
2. Key Constraints
3. Referential Integrity Constraints

Domain Constraints
Domain constraints can be violated if an attribute value is
not appearing in the corresponding domain or it is not of the
appropriate data type.

Domain constraints specify that within each tuple, and the


value of each attribute must be unique. This is specified as
data types which include standard data types integers, real
numbers, characters, Booleans, variable length strings, etc.

Example:
Create DOMAIN CustomerName
CHECK (value not NULL)

The example shown demonstrates creating a domain constraint such


that

CustomerName is not NULL Key Constraints

An attribute that can uniquely identify a tuple in a relation is


called the key of the table. The value of the attribute for
different tuples in the relation has to be unique.

Example:

In the given table, CustomerID is a key attribute of


Customer Table. It is most likely to have a single key for one
customer, CustomerID =1 is only for the CustomerName ="
Google".
CustomerID CustomerName Status

1 Google Active

2 Amazon Active
3 Apple Inactive

Referential Integrity Constraints


Referential Integrity constraints in DBMS are based on the
concept of Foreign Keys. A foreign key is an important
attribute of a relation which should be referred to in other
relationships. Referential integrity constraint state happens
where relation refers to a key attribute of a different or same
relation.
However, that key element must exist in the table.

In the above example, we have 2 relations, Customer and


Billing.

Tuple for CustomerID =1 is referenced twice in the relation


Billing. So we know CustomerName=Google has billing
amount $300
Operations in Relational Model
Four basic update operations performed on relational
database model are

Insert, update, delete and select.


• Insert is used to insert data into the relation  Delete is
used to delete tuples from the table.
• Modify allows you to change the values of some
attributes in existing tuples.
• Select allows you to choose a specific range of data.

Whenever one of these operations are applied, integrity


constraints specified on the relational database schema
must never be violated. Insert Operation

The insert operation gives values of the attribute for a new


tuple which should be inserted into a relation.

Update Operation
You can see that in the below-given relation table
CustomerName= 'Apple' is updated from Inactive to Active.

Delete Operation
To specify deletion, a condition on the attributes of the
relation selects the tuple to be deleted.
In the above-given example, CustomerName= "Apple" is
deleted from the table.

The Delete operation could violate referential integrity if the


tuple which is deleted is referenced by foreign keys from
other tuples in the same database.

Select Operation

In the above-given example, CustomerName="Amazon" is


selected

Best Practices for creating a Relational Model


• Data need to be represented as a collection of
relations
• Each relation should be depicted clearly in the table
• Rows should contain data about instances of an entity
• Columns must contain data about attributes of the
entity
• Cells of the table should hold a single value
• Each column should be given a unique name
• No two rows can be identical
• The values of an attribute should be from the same
domain

Advantages of using Relational Model


• Simplicity: A Relational data model in DBMS is
simpler than the hierarchical and network model.
• Structural Independence: The relational database is
only concerned with data and not with a structure.
This can improve the performance of the model.
• Easy to use: The Relational model in DBMS is easy
as tables consisting of rows and columns are quite
natural and simple to understand
• Query capability: It makes possible for a high-level
query language like SQL to avoid complex database
navigation.
• Data independence: The Structure of Relational
database can be changed without having to change
any application.
• Scalable: Regarding a number of records, or rows,
and the number of fields, a database should be
enlarged to enhance its usability.

Disadvantages of using Relational Model


• Few relational databases have limits on field lengths
which can't be exceeded.
• Relational databases can sometimes become
complex as the amount of data grows, and the
relations between pieces of data become more
complicated.
• Complex relational database systems may lead to
isolated databases where the information cannot be
shared from one system to another.

DBMS 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. Key is also helpful for finding unique record or
row from the table. Database key is also helpful for finding
unique record or row from the table.

Example:
Employee FirstName LastName
ID

11 Andrew Johnson

22 Tom Wood

33 Alex Hale
In the above-given example, employee ID is a primary key
because it uniquely identifies an employee record. In this
table, no other employee can have the same employee ID.

Types of Keys in Database Management


System
There are mainly seven different types of Keys in DBMS
and each key has it’s different functionality:

• Super Key - A super key is a group of single or


multiple keys which identifies rows in a table.
• Primary Key - is a column or group of columns in a
table that uniquely identify every row in that table.
• Candidate Key - is a set of attributes that uniquely
identify tuples in a table. Candidate Key is a super key
with no repeated attributes.
• Alternate Key - is a column or group of columns in a
table that uniquely identify every row in that table.
• Foreign Key - is a column that creates a relationship
between two tables. The purpose of Foreign keys is to
maintain data integrity and allow navigation between
two different instances of an entity.
• Compound Key - has two or more attributes that
allow you to uniquely recognize a specific record. It is
possible that each column may not be unique by itself
within the database.
• Composite 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.
• 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.

• What is the 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.

What is a Primary Key?


PRIMARY KEY is a column or group of columns in a table
that uniquely identify every row in that table. The Primary
Key can't be a duplicate meaning the same value can't
appear more than once in the table. A table cannot have
more than one primary key.

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, <code>StudID</code> is a
Primary Key.
What is the Alternate key?
ALTERNATE KEYS is a column or group of columns in a
table that uniquely identify every row in that table. A table
can have multiple choices for a primary key but only one
can be set as the primary key. All the keys which are not
primary key are called an Alternate 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 First LastName Email
No Name

1 11 Tom Price abc@gmail.com

2 12 Nick Wright xyz@gmail.com

3 13 Dana Natan mno@yahoo.com

What is a Candidate Key?


CANDIDATE KEY is a set of attributes that uniquely identify
tuples in a table. Candidate Key is a super key with no
repeated attributes. The Primary key should be selected
from the candidate keys. Every table must have at least a
single candidate key. A table can have multiple candidate
keys but only a single primary 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 First LastName Email
No Name

1 11 Tom Price abc@gmail.com

2 12 Nick Wright xyz@gmail.com

3 13 Dana Natan mno@yahoo.com

What is the Foreign key?


FOREIGN KEY is a column that creates a relationship
between two tables. The purpose of Foreign keys is to
maintain data integrity and allow navigation between two
different instances of an entity. It acts as a cross-reference
between two tables as it references the primary key of
another table.

Example:
DeptCode DeptName

001 Science

002 English
005 Computer

Teacher Fname Lname


ID

B002 David Warner


B017 Sara Joseph

B009 Mike Brunton

In this key in dbms 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 DeptCode Fname Lname
ID

B002 002 David Warner

B017 002 Sara Joseph

B009 001 Mike Brunton

This concept is also known as Referential Integrity.

What is the Compound key?


COMPOUND KEY has two or more attributes that allow you
to uniquely recognize a specific record. It is possible that
each column may not be unique by itself within the
database. However, when combined with the other column
or columns the combination of composite keys become
unique. The purpose of the compound key in database is to
uniquely identify each record in the table.
Example:

OrderNo PorductID Product Quantity


Name

B005 JAP102459 Mouse 5

B005 DKT321573 USB 10

B005 OMG446789 LCD 20


Monitor

B004 DKT321573 USB 15

B002 OMG446789 Laser 3 Printer

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.

What is the Composite key?


COMPOSITE KEY is a combination of two or more columns
that uniquely identify rows in a table. The combination of
columns guarantees uniqueness, though individually
uniqueness is not guaranteed. Hence, they are combined to
uniquely identify records in a table.

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.

Integrity Constraints
o Integrity constraints are a set of rules. It is used to maintain
the quality of information.
o Integrity constraints ensure that the data insertion, updating,
and other processes have to be performed in such a way that
data integrity is not affected.

o Thus, integrity constraint is used to guard against accidental


damage to the database.

Types of Integrity Constraint

Entity integrity constraints

o The entity integrity constraint states that primary key value


can't be null.

o This is because the primary key value is used to identify


individual rows in relation and if the primary key has a null
value, then we can't identify those rows.

o A table can contain a null value other than the primary key
field.

Example:

3.
Referential Integrity Constraints

o A referential integrity constraint is specified between two


tables.
o In the Referential integrity constraints, if a foreign key in
Table 1 refers to the Primary Key of Table 2, then every value
of the Foreign Key in Table 1 must be null or be available in
Table 2.

Example:

Normalization Process in DBMS


Normalization is a systematic approach to organize data in a database to
eliminate redundancy, avoid anomalies and ensure data consistency. The process
involves breaking down large tables into smaller, well-structured ones and
defining relationships between them. This not only reduces the chances of
storing duplicate data but also improves the overall efficiency of the database.
 A relation in BCNF is also in 3NF , a relation in 3NF is also in 2NF and a relation
in 2NF is also in 1NF.
 A relation in BCNF is considered fully normalized.

First Normal Form:


If a relation contains a composite or multi-valued
attribute, it violates the first normal form, or the
relation is in the first normal form if it does not
contain any composite or multi-valued attribute. A
relation is in first normal form if every attribute in
that relation is single-valued attribute.
A table is in 1 NF if:
 There are only Single Valued Attributes.
 Attribute Domain does not change.
 There is a unique name for every Attribute/Column.
 The order in which data is stored does not matter.
Rules for First Normal Form (1NF) in DBMS
To follow the First Normal Form (1NF) in a database,
these simple rules must be followed:
1. Every Column Should Have Single Values
Each column in a table must contain only one value
in a cell. No cell should hold multiple values. If a cell
contains more than one value, the table does not
follow 1NF.
 Example: A table with columns like [Writer 1],
[Writer 2], and [Writer 3] for the same book ID is not
in 1NF because it repeats the same type of
information (writers). Instead, all writers should be
listed in separate rows.
2. All Values in a Column Should Be of the
Same Type
Each column must store the same type of data. You
cannot mix different types of information in the
same column.
 Example: If a column is meant for dates of birth
(DOB), you cannot use it to store names. Each type
of information should have its own column.
3. Every Column Must Have a Unique Name
Each column in the table must have a unique name.
This avoids confusion when retrieving, updating, or
adding data.
 Example: If two columns have the same name, the
database system may not know which one to use.
4. The Order of Data Doesn’t Matter
In 1NF, the order in which data is stored in a table
doesn’t affect how the table works. You can organize
the rows in any way without breaking the rules.
Example:

 In the above table, Courses has a multi-valued


attribute, so it is not in 1NF. The Below Table is in
1NF as there is no multi-valued attribute.
Second Normal Form (2NF)
Second Normal Form (2NF) is based on the concept of fully
functional dependency. It is a way to organize a database
table so that it reduces redundancy and ensures data
consistency. For a table to be in 2NF, it must first meet the
requirements of First Normal Form (1NF), meaning all
columns should contain single, indivisible values without any
repeating groups.
Example-1: Consider the table below.

 There are many courses having the same course fee. Here,
COURSE_FEE cannot alone decide the value of COURSE_NO or
STUD_NO.
 COURSE_FEE together with STUD_NO cannot decide the value
of COURSE_NO.
 COURSE_FEE together with COURSE_NO cannot decide the
value of STUD_NO.
 The candidate key for this table is {STUD_NO,
COURSE_NO} because the combination of these two columns
uniquely identifies each row in the table.
 COURSE_FEE is a non-prime attribute because it is not part of
the candidate key {STUD_NO, COURSE_NO}.
 But, COURSE_NO -> COURSE_FEE, i.e., COURSE_FEE is
dependent on COURSE_NO, which is a proper subset of the
candidate key.
 Therefore, Non-prime attribute COURSE_FEE is dependent on
a proper subset of the candidate key, which is a partial
dependency and so this relation is not in 2NF.
To convert the above relation to 2NF, we need to split the
table into two tables such as : Table 1: STUD_NO,
COURSE_NO Table 2: COURSE_NO, COURSE_FEE.

Now, each table is in 2NF:


 The Course Table ensures that COURSE_FEE depends only
on COURSE_NO.
 The Student-Course Table ensures there are no partial
dependencies because it only relates students to courses.
Third Normal Form (3NF)
A relation that is in First and Second Normal Form
and in which no non-primary-key attribute is
transitively dependent on the primary key, then it is
in Third Normal Form (3NF).
If A->B and B->C are two FDs then A->C is called
transitive dependency. The normalization of 2NF relations
to 3NF involves the removal of transitive dependencies. If
a transitive dependency exists, we remove the
transitively dependent attribute(s) from the relation by
placing the attribute(s) in a new relation along with a
copy of the determinant.
In the relation CANDIDATE given above:
 Functional dependency Set: {CAND_NO -> CAND_NAME,
CAND_NO ->CAND_STATE, CAND_STATE -> CAND_COUNTRY,
CAND_NO -> CAND_AGE}
 So, Candidate key here would be: {CAND_NO}
 For the relation given here in the table, CAND_NO ->
CAND_STATE and CAND_STATE -> CAND_COUNTRY are
actually true. Thus, CAND_COUNTRY depends transitively on
CAND_NO. This transitive relation violates the rules of being
in the 3NF. So, if we want to convert it into the third normal
form, then we have to decompose the relation CANDIDATE
(CAND_NO, CAND_NAME, CAND_STATE, CAND_COUNTRY,
CAND_AGE) as:
CANDIDATE (CAND_NO, CAND_NAME, CAND_STATE,
CAND_AGE) STATE_COUNTRY (STATE, COUNTRY).
BCNF
Boyce-Codd Normal Form (BCNF) is a stricter version of Third
Normal Form (3NF) that ensures a more simplified and efficient
database design. It enforces that every non-trivial functional
dependency must have a superkey on its left-hand side. This
approach addresses potential issues with candidate keys and
ensures the database is free from redundancy.
BCNF eliminates redundancy more effectively than 3NF by strictly
requiring that all functional dependencies originate from super-
keys.
BCNF is essential for good database schema design in higher-level .
Rule 1: The table should be in the 3rd Normal Form.
Rule 2: X should be a super-key for every functional dependency
(FD) X−>Y in a given relation.
Example 1
Consider a relation R with attributes (student, teacher, subject).

 Candidate keys are (student, teacher) and (student, subject).


 The above relation is in 3NF (since there is no transitive
dependency). A relation R is in BCNF if for every non-trivial
FD X->Y, X must be a key.
 The above relation is not in BCNF, because in the FD (teacher-
>subject), teacher is not a key. This relation suffers with
anomalies −
 For example, if we delete the student Tahira , we will also lose
the information that N.Gupta teaches C. This issue occurs
because the teacher is a determinant but not a candidate
key.

Fourth Normal Form (4NF)


Any relation is said to be in the fourth normal form when
it satisfies the following conditions:
 It must be in Boyce Codd Normal Form (BCNF).
 It should have no multi-valued dependency.
 A multi-valued dependency is said to occur when there are
two attributes in a table which depend on a third attribute
but are independent of each other. For a functional
dependency X->Y there will be a multi-valued dependency
if there exists multiple values of Y for a single value of X.
Thus if a relation is in BCNF and also it does not have any
kind of multi-valued dependency then that relation will be
in 4NF. In order to denote a multi-valued dependency, “->-
>” this sign is used.
 Example:
 Consider the following relation:
Student- Cours Hobb
ID e y

Scienc Dancin
100
e g
Student- Cours Hobb
ID e y

Singin
100 Maths
g

Dancin
101 C#
g

Singin
101 PHP
g

 In this relation Student-ID 1 has thus opted for two courses


and has two hobbies. Similarly Student-ID 2 has opted for
two courses and has two hobbies. Thus it contains multi-
valued dependencies. It is not in 4NF and in order to
convert it into 4NF it can be decomposed into two relations:
 Table –
 R1
Student- Cours
ID e

Scienc
100
e

100 Maths

101 C#

101 PHP

 Table –
 R2
Student- Hobb
ID y

Dancin
100
g

Singin
100
g
Student- Hobb
ID y

Dancin
101
g

Singin
101
g

 Now this relation is thus in 4NF. A relation can contain a


functional dependency along with a multi-valued
dependency also.So when such a case arises the columns
which are functionally dependent are moved to a separate
table and the columns which are multi-valued dependent
are moved to a separate table. This converts the relation
into 4NF.

Fifth Normal Form (5NF)


Any relation in order to be in the fifth normal form must satisfy the
following conditions:
 It must be in Fourth Normal Form (4NF).
 It should have no join dependency and also the joining must be
lossless.
In the fifth normal form the relation must be decomposed in as many
sub-relations as possible so as to avoid any kind of redundancy and
there must be no extra tuples generated when the sub-relations are
combined together by using natural join. A relation in 5NF cannot be
decomposed further without any kind of modification in the meaning
or facts.
Example –

Student- Mobile
ID Number Hobby

Dancin
123 9999900000
g

124 9999900000 Singing

Dancin
124 9999900000
g
Student- Mobile
ID Number Hobby

123 8975622122 Singing

123 9999900000 Singing

This can be further decomposed into three relations:


Table –
R1

Mobile
Student-ID Number

123 9999900000

123 8975622122

124 9999900000

Table –
R2

Student-ID Hobby

Dancin
123
g

123 Singing

124 Singing

Dancin
124
g

Table –
R3
Mobile
Number Hobby

Dancin
9999900000
g

9999900000 Singing

8975622122 Singing

Thus if natural join is performed on all the three relations then there
will be no extra tuples. Hence R1, R2 and R3 are in fifth normal form
(5NF).

Converting Conceptual Models to Relational Databases.


https://slideplayer.com/slide/13074251/

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy