Database SQL W2
Database SQL W2
▪ 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)
▪ 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.
▪ 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
▪ 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:
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: