DBMS. Module 3 Notes
DBMS. Module 3 Notes
Semester: 4B
Course Name: DBMS
Course Code:BCS403
Credit Points: 4
Name of the Course Instructor: Dr. Jansi Rani J
Refered BooK:
1. Fundamentals of Database Systems, Ramez Elmasri and Shamkant B. Navathe, 7th
Eclititln, 2017, Pearson
2. Database management systems, Ramakrishnan, and Gehrke, 3rd Edition, 2014,
McGraw Hill
Module 3 Topics
Normalization: Database Design Theory – (Text BOOK1 Ch 14.1 to
14.7)
Introduction to Normalization using Functional and Multivalued
Dependencies:
Informal design guidelines for relation schema,
Functional Dependencies
Normal Forms based on Primary Keys,
Second and Third Normal Forms,
Boyce-Codd Normal Form,
Multivalued Dependency and Fourth Normal Form,
Join Dependencies and Fifth Normal Form.
SQL-(Text BOOK1 Ch 16.1 to 6.5)
SQL data definition and data types,
Schema change statements in SQL,
specifying constraints in SQL,
retrieval queries in SQL,
INSERT, DELETE, and UPDATE statements in SQL,
1. Define Normalization:
Database normalization is a technique of organizing the data in the database.
Normalization is a systematic approach of decomposing tables
To eliminate data redundancy and
To eliminate undesirable characteristics like insertion, update and deletion
anomalies.
2. Explain the informal guidelines used to determine the quality of
relation schema design.
Four informal guidelines help ensure a database is efficient, meaningful,
and error-free.
Making sure that the semantics of the attributes is clear in the schema.
Reducing the redundant information in tuples.
Reducing the NULL values in tuples.
Disallowing the possibility of generating spurious tuples.
Guideline 1:
Design a relation schema so that it is easy to explain its meaning.
Do not combine attributes from multiple entity types and relationship types into a
single relation
Mixed different entities in a single table. Good design of table should have
single entity like
By Dr. Jansi Rani J, Dr. TTIT,KGF
EMPLOYEE(EmpName, DeptID)
1. Insertion Anomaly
Example:
2. Deletion Anomaly
Example:
3. Update Anomaly
Example:
If many of the attributes do not apply to all tuples in the relation, we end up with many
NULLs,
This can waste space at the storage level.
May lead to problems with understanding the meaning of the attributes.
May also lead to problems with specifying JOIN operations.
Example:
STUDENT(Name, Phone, HostelRoom)
Many students may not have hostel → NULL values
Design the table as
STUDENT(Name, Phone)
HOSTEL(StudentID, Room)
iv. Avoid Spurious Tuples:
v. Spurious tuples are unintended and erroneous rows that can be generated when two tables are
joined improperly.
By Dr. Jansi Rani J, Dr. TTIT,KGF
vi. This typically occurs when there is an incorrect or incomplete join condition, often due to the
lack of proper primary and foreign key constraints or missing relationships between the tables.
vii. Spurious tuples can lead to incorrect query results and data anomalies.
Functional Dependencies
A functional dependency, denoted by X → Y means that the values of the Y are determined by the
values of X .
X = determinant
Y = dependent attribute
X → Y means, Value of Y depends on value of X
Ex: a. ssn→ename
b. pnumber →{pname, plocation}
c. {ssn, pnumber}→hours
These functional dependencies specifies that
(a) the value of an employee‘s social security number (ssn) uniquely determines the employee
name (ename),
(b) the value of a project‘s number (pnumber) uniquely determines the project name (pname)
and location (plocation),
(c) combination of ssn and pnumber values uniquely determines the number of hours the
employee currently works on the project per week (hours).
Types of functional dependency
1. Full functional dependency- A functional dependency X → Y is called a
Full Functional Dependency if Y depends on the entire set of attributes in X. If
you remove even one attribute from X → then not full dependency.
Example
{Ssn, Pnumber} → Hours
if you remove:
Ssn → Hours (not valid)
Pnumber → Hour (not valid) both together are required.
Therefore:
A super key is a set of one or more attributes that can uniquely identify each row in a table.
A super key may contain extra attributes.
Stronger version of 3NF
Removes anomalies not handled by 3NF
Example
Student Course Instructor
Course → Instructor
Student + Course → Instructor
Course is not a key → violates BCNF
Split into
COURSE(Course, Instructor)
Course Instructor
ADA Ashwini
ENROLLMENT(Student, Course)
Student Course
David ADA
STUDENT_HOBBY
Stude Hobb
nt y
Cricke
John
t
John Music
STUDENT_LANGUAGE
Student Language
John English
John Hindi
Supplier Part
S1 P1
S1 P2
S2 P1
SUPPLIER_PROJECT
PART_PROJECT
Part Project
P1 J1
P2 J1
Normal
Rule Removes
Form
No repeating groups
Repeating
1NF or multivalued
data
attributes
Must be in 1NF and
Partial
2NF no partial
dependency
dependency
Must be in 2NF and
Transitive
3NF no transitive
dependency
dependency
Every determinant
Dependency
BCNF must be a candidate
anomalies
key
Must be in BCNF
Multivalued
4NF and no multivalued
dependency
dependency
Must be in 4NF and Join
5NF
no join dependency dependency
Functional Dependencies
OrderID →CustomerName , CustomerCityProductID → ProductName , SupplierID
Candidate Key:
( OrderID , ProductID )
1NF (First Normal Form)
Rule
No repeating groups
Atomic values only
The given table already contains:
single values
no multivalued attributes
So it is already in 1NF.
PRODUCT
Product
ProductID SupplierID
Name
P1 Keyboard S1
P2 Mouse S2
By Dr. Jansi Rani J, Dr. TTIT,KGF
Product
ProductID SupplierID
Name
P3 Monitor S3
ORDER_ITEM
In PRODUCT table
ProductID → ProductName , SupplierID
ProductID is key
SUPPLIER
SupplierID → SupplierName
SupplierID is key
ORDER_ITEM
(OrderID , ProductID)→ Quantity , ProjectID
Composite key determines all
So all relations are in BCNF.
4NF (Fourth Normal Form)
Rule
Must be in BCNF
No multivalued dependency
Assume:
A supplier can supply many products independently
A project can use many products independently
Possible multivalued dependencies:
SupplierID ↠ ProductID ProjectID ↠ ProductID
SupplierID ProductID
S1 P1
By Dr. Jansi Rani J, Dr. TTIT,KGF S2 P2
S3 P3
PROJECT_PRODUCT
ProjectID ProductID
J1 P1
J1 P2
J2 P1
J2 P3
ORDER_ITEM
OrderID ProductID Quantity
O1 P1 2
O1 P2 1
O2 P1 3
O2 P3 1
Other tables remain same.
Now multivalued dependencies are removed.
5NF (Fifth Normal Form / PJNF)
Rule
Must be in 4NF
Remove join dependencies
No further lossless decomposition possible
Suppose relationship exists among:
Supplier
Product
Project
Then decompose into:
By Dr. Jansi Rani J, Dr. TTIT,KGF
SupplierID ProductID
ProductID ProjectID
| SupplierID | ProjectID |
SQL:
SQL Data Definition and Data Type
Data Definition Language (DDL) in SQL is used to define and manage the
structure of a database.
Data Type
SQL data types specify the kind of data that can be stored in a column.
. Numeric Data Types
The Data consist of numeric value can be represent as following
INT – Integer values
Example:
CREATE TABLE Student (Age INT);
FLOAT / REAL – Floating-point numbers
Example:
INSERT INTO Student VALUES (102, 76.25);
DECIMAL(p, s) – Fixed precision numbers (e.g., money).
Example:
o CREATE TABLE Product (ProductID INT,Price DECIMAL(6,2));
Character/String Data Types
BIT-STRING
Literal bit strings are placed between single quotes but preceded by a B to
distinguish them from character strings; for example, B‗10101‘.
BOOLEAN
The data type has the traditional values of TRUE or FALSE. In SQL, because
of the presence of NULL values, a three-valued logic is used, so a third
DATE
The data type has ten positions, and its components are YEAR, MONTH,
and DAY in the form YYYY-MM-DD.
By Dr. Jansi Rani J, Dr. TTIT,KGF
The TIME data type has at least eight positions, with the components
HOUR, MINUTE, and SECOND in the form HH:MM:SS. for example,
Example: CREATE TABLE Student (RollNo INT, Name VARCHAR(50), DOB DATE);
TIMESTAMP
The data type (TIMESTAMP) includes the DATE and TIME fields,
Example: CREATE TABLE ClassSchedule (Subject VARCHAR(50), StartTime
TIME);
SELECT Clause:
This clause is used to specify the columns that you want to retrieve from
the database. It can also include expressions, functions, and even
subqueries.
Example: SELECT Name, Age
FROM Student;
FROM Clause:
This clause specifies the table(s) from which to retrieve the data. It can
also include joins to combine data from multiple tables.
Syntax: SELECT column_name
FROM table_name;
SELECT Name, Age
FROM Student;
WHERE Clause:
This clause is used to filter records that meet certain conditions. It can
include various operators and conditions.
Example: SELECT Name FROM Student WHERE Age > 15;
GROUP BY Clause:
This clause groups rows that have the same values in specified columns
into summary rows. It is often used with aggregate functions like
COUNT, SUM, AVG, etc.
GROUP BY Department;
HAVING Clause:
ORDER BY Clause:
2. UNIQUE Constraint: Ensures that all the values in a column are different.
CREATE TABLE Students (
StudentID int NOT NULL,
Email varchar(255) UNIQUE
);