Designing Databases
Data modeling has 4 steps-
Understand the requirements
Build a Conceptual Model
Build a Logical Model
Build a Physical Model
Understand the requirements
Ask requirements from client or user what they require in the database.
Conceptual Models
The purpose of the conceptual design phase is to build a conceptual model based upon the
previously identified requirements, but closer to the final physical model
Represents the entities and their relationships. eg: student ,course
Entity Relationship(ER)
UML(UNIFIED MODELLING LANGUAGE ) * Scope above the data modeling
We are using Entity Relationship(ER)
Using draw.io
Logical Models
Logical data modeling is where you will define the entities which will eventually become
tables, it's attributes (columns) and how the entities inter-relate with each other.
Basically add more details to our conceptual model
Then we have to define the relationship
One-to-one
One-to-many
Many-to-one
Many-to-many
Eg: This example is Many-to-Many
as a student can be enrolled to many course and a course have many students
Physical Model
A physical model is the implementation of the logical model for specific database
technologies, A physical data model can be used to generate DDL statements which can then
be deployed to a database server
Primary key
A primary key is the column or columns that contain values that uniquely identify each
row in a table.
Foreign Key
A foreign key is a column or columns of data in one table that refers to the unique data
values -- often the primary key data -- in another table.
Normalization
Normalization is a process of reviewing the design and ensures that it follows a few pre
defined rules that prevent data duplication.
Normalization is a formal approach that applies a set of rules to associate attributes
with entities.
When you normalize your data model, you can achieve the following goals. You can:
Produce greater flexibility in your design.
Ensure that attributes are placed in the correct tables.
Reduce data redundancy.
Increase programmer effectiveness.
Lower application maintenance costs.
Maximize stability of the data structure.
There are basically 7 rules which means there are 7 Normal forms but in 99% case we only
need three Normal Form.
1st Normal From
2nd Normal Form
3rd Normal Form
1NF-First Normal Form
Each cell in a row should have a single value and we cannot have repeated columns.
Tags in courses can have repeated values which violates our first normal form rule so we need
to find solution
2NF-Second Normal Form
1) It should be in first normal form .
2) Every table should describe one entity, and every column in that table should describe
that entity.
3) To convert first-normal-form tables to second-normal-form tables, remove columns
that are not dependent on the primary key.
3NF-Third Normal Form
1) The third normal form means that no column within a table is dependent on a
descriptor column that, in turn, depends on the primary key.
2) To convert to third normal form, remove attributes that depend on other descriptor key
attributes.