0% found this document useful (0 votes)
4 views

Database SQL W2

The document provides an overview of relational database design, including key concepts such as entities, attributes, relationships, and normalization. It explains the importance of data integrity and the role of Entity-Relationship Diagrams (ERDs) in visualizing database structures. Additionally, it covers various types of relationships and cardinality in database design.

Uploaded by

Kiều Linh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Database SQL W2

The document provides an overview of relational database design, including key concepts such as entities, attributes, relationships, and normalization. It explains the importance of data integrity and the role of Entity-Relationship Diagrams (ERDs) in visualizing database structures. Additionally, it covers various types of relationships and cardinality in database design.

Uploaded by

Kiều Linh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Week 2

Relational Database Design


Relational Database
▪ Basics of Relational Databases

▪ Keys: Primary, Foreign

▪ Entity-Relationship (ER) Modeling (Entities, Attributes, Relationships, ER Diagrams)

▪ Database Normalization
What is a Relational Database?
A relational database is a collection of information that organizes data in predefined
relationship 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.
Relationships are a logical connection between different tables, established on the basis of
interaction among these tables.
What is a Relational Database?
Relational Database Management System (RDBMS)

▪ Relational databases consist of


data stored in multiple tables.

▪ RDBMS serves as an interface to


access and manage relational
database, using SQL.

▪ RDBMS administrators can grant


access to users and set specific
roles and permissions.
Database Terms
▪ Entity: an entity represents a real-world object or concept that we want to store
information about in the database. (Ex: customer, product, student, employee,…)

▪ Attribute: a characteristic or property of an entity. (Ex: ”student” entity: ID, name, phone)

▪ Table: a two-dimensional structure with rows and columns used to store data in a
relational database. Each column represent an attribute of the entity. Each row represents
a record of an entity.

▪ Primary Key: a unique identifier for each row in a table. It ensures that each row is distinct.
A primary key cannot contain null values

▪ Foreign Key: a column in one table that references the primary key of another table.
Foreign keys establish relationship between tables.

▪ Relationship: a relationship defines how two or more entities are associated with each
other.
Database Terms
▪ Join: An operation that combines rows from two or more tables based on a related
column.

▪ Index: a data structure that improves the performance of data retrieval operations by
creating a sorted representation of the data in a table.

▪ View: A virtual table that is dynamically generated from one or more underlying tables.

▪ Stored Procedure: a pre-compiled collection of SQL statements that can be executed as a


single unit.

▪ Trigger: a special type of stored procedure that is automatically executed when a specific
event occurs in a table, such as an INSERT, UPDATE, or DELETE statement.
What is Database Design?
Database design is the process of creating an efficient an organized structure for storing and
managing data in a database. It involves defining tables, columns, relationships, and
constraints to ensure data integrity, minimize redundancy, and optimize performance. Proper
database design is the foundation for building robust and scalable applications.

src: https://dev.to/louaiboumediene/mastering-relational-database-design-a-comprehensive-guide-3jh8
Data Integrity
Data integrity refers to the accuracy, consistency, and reliability of data stored in a database. It
ensures that the data follows specific rules and constraints, preventing errors and
inconsistencies. There are three types of data integrity:

1. Entity Integrity: This ensures that there are no duplicate rows in a table.

2. Referential Integrity: Rows cannot be deleted, which are used by other records.

3. Domain Integrity: Enforces valid entries for a given column by restricting the data type,
format, and range of values that can be stored.
What is Database Normalization?
Database normalization is the process of efficiently organizing data in a database. There are
two reasons of this normalization process:

▪ Eliminating redundant data (Ex: storing the same data in more than one table).
▪ Ensuring data dependencies make sense.

This is to make sure that they reduce the amount of space a database consumes and ensures
that data is logically stored. Normalization consists of a series of guidelines that help guide
you in creating a good database structure.

Normalization guidelines are divided into normal forms, which are the format or the way a
database structure is laid out. The aim of normal forms is to organize the database structure,
so that it complies with the rules of
▪ First normal form (1NF)
▪ Second normal form (2NF)
▪ Third normal form (3NF)
What is an Entity-Relationship Diagram (ERD)?
An entity relationship diagram (ERD) is a visual representation of the entities, attributes, and
relationships within a database. It helps in designing the database schema.

An ERD contains different symbols and connectors that visualize two important information:
The major entities within the system scope, and the inter-relationships among these entities.
ERD Notations
Entity is a definable thing or concept within a system, for example

▪ Person/Role: Teacher, Student


▪ Object: Invoice, Order
▪ Concept: Profile
▪ Event: Transaction
Entity Attributes is a property or characteristic of the entity that holds it. For example, a
customer may have attributes as following:

▪ ID
▪ First_Name
▪ Last_Name
▪ Address
▪ Telephone
▪ Gender
▪ Active
▪ Email
▪ Create_Date
▪ Last_Update
ERD Notations
Primary Key (PK) is a special kind of entity attribute that uniquely defines a record in a
database table. In other words, there must not be two (or more) records that share the same
value for the primary key attribute.

Example: The ERD example below shows an entity “Product” with a primary key attribute
“ID”, and a preview of table records in the database. The third record is invalid because of ID
“PDT-0002” is already used by another record.
ERD Notations
Foreign Key (FK) is a reference to a primary key in a table. It is used to identify the
relationships between entities. Note that foreign keys need not be unique. Multiple records
can share the same values. The ER Diagram example below shows an entity with some
columns, among which a foreign key is used in referencing another entity.
Relationship
Relationship defines how two or more entities are associated with each other. There are three
main types of relationships:

▪ One-to-One Relationship: is mostly used to split an entity in two to provide information


concisely and make it more understandable.

▪ One-to-Many Relationship: refers to the relationship between two entities X and Y in


which an instance of X may be linked to many instances of Y, but an instance of Y is linked
to only one instance of X.

▪ Many-to-Many Relationship: refers to the relationship between two entities X and Y, in


which X may be linked to many instances of Y and vice versa. Note that a many-to-many
relationship is split into a pair of one-to-many relationships in a physical ERD.
Cardinality
Cardinality defines the possible number of occurrences in one entity which is associated with
the number of occurrences in another.

Example: ONE Team has MANY Players. When present in an ERD, the entity Team and Player
are inter-connected with a one-to-many relationship.
Cardinality
▪ One-to-One Relationship:

▪ One-to-Many Relationship:

▪ Many-to-Many Relationship:

You might also like