23
Data Base Normalization And Entity Relationship Diagrams 03/16/2022 1

Data Base Normalization and ERD

  • Upload
    sxurdc

  • View
    28

  • Download
    2

Embed Size (px)

DESCRIPTION

Database Normalization and ERD Basics

Citation preview

04/18/2023 1

Data Base NormalizationAnd

Entity Relationship Diagrams

04/18/2023 2

Normalization

• Database normalization is the process of removing redundant data from your tables in to improve storage efficiency, data integrity, and scalability.

• Normalization generally involves splitting existing tables into multiple ones, which must be re-joined or linked each time a query is issued.

• Edgar F. Codd originally established three normal forms: 1NF, 2NF and 3NF. There are now others that are generally accepted, but 3NF is widely considered to be sufficient for most applications. Most tables when reaching 3NF are also in BCNF (Boyce-Codd Normal Form).

04/18/2023 3

1st Normal Form

Rules of First Normal Form1. Create separate tables for each group of

related data and ensure each row is unique by identifying a primary key .

2. Eliminate duplicate columns from the same table.

**Primary key : A primary key is either a single field or combined set of fields that

uniquely identify a single row of data in a table

04/18/2023 4

1st Normal Form Example

• Let say we want to build a database that can manage Books.

• We can create an entity(table) like thisEntity Book

Fields

Title

Author1

Author2

ISBN

Subject

Pages

Publisher

Title Author1 Author2 ISBN SubjectPages

Publisher

Database System Concepts

Abraham Silberschatz

Henry F. Korth

72958863

MySQL, Computers

1168

McGraw-Hill

Operating System Concepts

Abraham Silberschatz

Henry F. Korth

471694665 Computers 944

McGraw-Hill

04/18/2023 5

1st Normal Form

• In our Table 1, we have two violations of First Normal Form:

• First, we have more than one author field, • Second, our subject field contains more than

one piece of information. With more than one value in a single field, it would be very difficult to search for all books on a given subject.

04/18/2023 6

1st Normal FormBefore Normalization

Title Author1 Author2 ISBN Subject Pages PublisherDatabase System

ConceptsAbraham

SilberschatzHenry F.

Korth 72958863MySQL,

Computers 1168McGraw-

HillOperating System

ConceptsAbraham

SilberschatzHenry F.

Korth47169466

5 Computers 944McGraw-

Hill

1st Normal FormTitle Author ISBN Subject Pages Publisher

Database System Concepts

Abraham Silberschatz 72958863 MySQL 1168

McGraw-Hill

Database System Concepts Henry F. Korth 72958863

Computers 1168

McGraw-Hill

Operating System Concepts Henry F. Korth 471694665

Computers 944

McGraw-Hill

Operating System Concepts

Abraham Silberschatz 471694665

Computers 944

McGraw-Hill

We now have two rows for a single book. Additionally, we would be violating the Second Normal Form.A better solution to our problem would be to separate the data into separate tables- an Author table and a Subject table to store our information, removing that information from the Book table:

04/18/2023 7

1st Normal Form

1stNormal Form

Subjects Table Authors TableSubject_ID Subject Author_ID Last Name First Name

1 MySQL 1 Silberschatz Abraham2 Computers 2 Korth Henry

Books Table

ISBN TitlePage

s Publisher

72958863Database System

Concepts 1168McGraw-

Hill

471694665Operating System

Concepts 944McGraw-

Hill

04/18/2023 8

2nd Normal Form

• Meet all the requirements of 1st Normal Form.• Remove redundant data and place them in

separate tables• Create relationships between tables through

the use of foreign keys.

Foreign Key : The foreign key create the foundation of a relationship between two tables by inserting the primary key from one table into another table

04/18/2023 9

2nd Normal FormPublisher Table

Publisher_ID Publisher Name1 McGraw-Hill

Books TableISBN Title Pages Publisher_ID

72958863 Database System Concepts 1168 1471694665 Operating System Concepts 944 1

Here we have a one-to-many relationship between the book table and the publisher. A book has only one publisher, and a publisher will publish many books. When we have a one-to-many relationship, we place a foreign key in the Book Table, pointing to the primary key of the Publisher Table.

04/18/2023 10

3rd Normal Form

• Meet all the requirements of 2nd Normal Form• Remove all attributes from a table that are not

directly dependant on primary key .

04/18/2023 11

Entity Relationship Diagrams

04/18/2023 12

Entity and Attribute

• An entity is a business object that represents a group, or category of data.

• An attribute is a sub-group of information within an entity.

• Entity Table• Attribute Column

04/18/2023 13

Entity Relationship Models

• Mandatory Relationships• Optional Relationships• Many-to-Many Relationships• One-to-Many Relationships• One-to-One Relationships• Recursive Relationships

04/18/2023 14

Mandatory, Many-to-Many

INSTRUCTOR STUDENT

INSTRUCTOR STUDENT

04/18/2023 15

Optional, Many-to-Many

DEPARTMENT STUDENT

DEPARTMENT STUDENT

04/18/2023 16

Optional/Mandatory,Many-to-Many

INSTRUCTOR SKILL

INSTRUCTOR SKILL

04/18/2023 17

Optional/Mandatory,One-to-Many

PRODUCT VENDOR

PRODUCT VENDOR

04/18/2023 18

Mandatory, One-to-One

AUTOMOBILE ENGINE

AUTOMOBILE ENGINE

04/18/2023 19

Recursive

EMPLOYEEsupervises

is supervised by

04/18/2023 20

Resolving Many-to-Many Relationships

• Many-to-many relationships should be avoided. We can resolve a many-to-many relationship by dividing it into two one-to-many relationships.

04/18/2023 21

Resolving Many-to-Many Relationships

SALES ORDERS INV. ITEMS

SALES ORDERS INV. ITEMSORDER ITEMS

04/18/2023 22

Example (ER Diagram)

SALES ORDERS

INV. ITEMSORDER ITEMS

CLERKSCUSTOMERS

HR Schema ER Diagram