Database Lecture Slides
Database Lecture Slides
& Development
Unit_04
01 02
ER Diagrams Normalization
How to design ER How to normalize a
Diagrams. database.
03 04
SQL Testing
How to write sql How to test the
queries. system and create
test plans.
01
ER
Diagrams
1.1 What is ER Diagram
(Entity Relationship Diagrams)
● Entities
● Attributes
● Relationships
● Cardinality
● Primary Key(PK) / Foreign Key(FK)
1.1.1 Entities
These are objects or concepts that can store data. In the diagram, entities are typically
represented by rectangles.
Ex : In a school database,
● Teachers
● Students
● Subjects are the entities.
1.1.2 Attributes
These are the data elements associated with entities. Attributes are often represented by
ovals connected to their corresponding entities.
Ex : In student entity,
● Student ID
● Student Name
● Student Birthday are the attributes.
1.1.2.1 Attribute Types
fist_name
Stu_name
Stu_name Stu_id
last_name Student
Student Stu_age
Multi-valued Single-valued
Attributes
Multi-valued attributes are Attributes
Single-valued attributes are attributes
attributes that can hold multiple that can hold only one value for a
values for a particular entity particular entity instance.
instance.
Stu_name Stu_name
mobile_
Stu_id Student number Stu_id Student
Stu_age Stu_age
Multi-valued
attribute
Derived Attributes Stored Attributes
Derived attributes are attributes Stored attributes are attributes whose
whose values are not stored values are directly stored in the
directly but are instead computed database.
or derived from other attributes.
Stu_name Stu_name
Stu_birthd
Stu_id Student ate Stu_id Student
Stu_age Stu_age
Derived attribute
1.1.3 Relationships
These describe how entities interact with each other. Relationships are typically depicted as
diamonds connected to the entities involved.
Ex : In school database,
Ex : In school database,
1 1 Report
Student has
card
One to Many (1:M)
Ex : In school database,
1 M
School has Classroom
Many to Many (M:N)
Ex : In school database,
M M
Student study Subject
1.1.5 Primary Key (PK)
Primary key is the unique identifier for each data row in a table.
● Minimal
● Not NULL value Stu_id Student
● Accessible
● Unique
Characteristics of Foreign
Key
● Minimal
● Not NULL value Stu_id Student
● Accessible
● Unique
cla_id
Primary Key & Foreign Key
Maplewood Library, nestled in a small town, is a beloved spot for readers like Anna and Mr. Baker. Each book in
the library has a unique ID, and members borrow these books regularly.
When Anna borrowed "The Great Gatsby" on August 1st, and Mr. Baker borrowed "A Brief History of Time" on
August 3rd, these events were recorded in the Loan system. Each loan connects a member to a specific book,
tracking the borrowing and return dates.
This simple yet effective system keeps Maplewood Library running smoothly, ensuring that members can enjoy their
favorite books whenever they visit.
Answers -
Bk_na Author_
Mem_ Mebersh Bk_id me name
Mem_id name ip_date
Member Book
1 M
Borrowed
Borrows
By
M Loan M
Loan Return
Loan_id Mem_id Bk_id
_date _date
02
Normalizatio
n
2.1 What is Normalization
● Normalization is the process of minimizing data redundancy and dependency
in database.
Why Normalization?
Enrollment Table
StudentID CourseID
101 CSE101
102 MAT101
101 MAT101
3rd Normal Form
Course Table
CourseID CourseName InstructorID
CSE101 Commerce 50
MAT101 Maths 51
Instructor Table
InstructorID InstructorName
50 Dr. Sam
51 Dr. Jones
Final tables after normalization
101 MAT101
03
SQL
3.1 What is SQL
SQL (Structured Query Language) is a standardized programming language used to manage and
manipulate relational databases.
Why SQL?
name VARCHAR(50),
department VARCHAR(50),
salary DECIMAL(10, 2) );
INSERT INTO employees (name, UPDATE employees SET salary = SELECT name, salary
department, salary) VALUES ('John 55000 WHERE name = 'John Doe'; FROM employees
Doe', 'Marketing', 50000); WHERE salary BETWEEN 40000
AND 60000;
● In Query ● Group By Query ● Order By Query
WHERE city IN ('New York', 'Los FROM employees ORDER BY name ASC;
● Having Query
● Testing methods are techniques which used to verify and validate that the software
functions are working correctly.
Testing Methods :
● Blackbox Testing
● Whitebox Testing
● System Testing
● Test Plan
● Refer this article for your further knowledge - Database Testing and Tools
4.2 Test Plan
● A test plan outlines the strategy, scope, resources, and schedule for the testing activities.
● It serves as a guide to ensure that testing is carried out systematically and that all critical
aspects of the software are covered.
Steps -
● Test case id
● Test case description
● Pre-conditions
● Post-condition
● Expected result
● Actual result
● Pass/Fail criteria
Test Case Example
Test Case Description Describe the function you are going to test.
Actual Result Write the result you received after executing the
function.