Week 5, DBMS
Week 5, DBMS
Week 5, DBMS
Azamat Serek
ERD
The Entity-Relationship Diagram (ERD) tool is a To open the ERD canvas, you can simply select
database design tool that provides a graphical a database and select ERD Tool from the Tools
representation of database tables, columns, and menu. You will get a blank canvas to create your
inter-relationships. An ERD can give sufficient ERD from scratch.
information for the database administrator to
follow when developing and maintaining the
database. pgAdmin allows you to create an ERD using an
existing database or table as well. You can right
click on a database, select “ERD for database”
option to generate an ERD from the database.
Generate ERD
Saving ERD
Export ERD
One to one
When a row in a table is related to only CREATE TABLE Country
one role in another table and vice
(
versa,we say that is a one to one
relationship. This relationship can be Pk_Country_Id INT IDENTITY
created using Primary key-Unique foreign PRIMARY KEY,
key constraints. Name VARCHAR(100),
Officiallang VARCHAR(100),
For instance a Country can only have one Size INT(11),
UN Representative, and also a UN
Representative can only represent one );
Country.
CREATE TABLE UNrepresentative INSERT INTO Country
('Name','Officiallang',’Size’)
(
VALUES ('Nigeria','English',923,768);
Pk_UNrepresentative_Id INT PRIMARY KEY,
Name VARCHAR(100),
INSERT INTO UNrepresentative
Gender VARCHAR(100), ('Pk_Unrepresentative_Id','Name','Gender'
,'Fk_Country_Id')
Fk_Country_Id INT UNIQUE FOREIGN KEY
REFERENCES Country(Pk_Country_Id) VALUES (51,'Abubakar Ahmad','Male',1);
);
One to many
CREATE TABLE Car CREATE TABLE Engineer
( (
);
INSERT INTO Car ('Brand','Model') INSERT INTO Engineer
('Pk_Engineer_Id','FullName','MobileN
o','Fk_Car_Id')VALUES(50,'Elvis
Young','08038888888',2);
VALUES ('Benz','GLK350');
); );
CREATE TABLE StudentClassRelation(
);
Normalization
Database normalization is a process by which
database and table structures are created or
modified in order to address
inefficiencies/complexities related to the
following:
● data storage
● data modification
● querying database tables
1NF
A 1NF database is an atomic database. In this
case, atomic means that each cell contains one
value and each row is unique. In the given
example, we can see that the non-atomic table
has cells with more than one value and
non-unique rows.
2NF
When a database is said to be 2NF, that means
the database is both 1NF and contains no partial
dependencies. A partial dependency is when an
attribute depends partly on the table’s primary key.
3NF
When making a 3NF database, two goals need to
be accomplished. The first being that the
database is already 2NF, and the second being
that the database contains no transitive functional
dependencies. A transitive functional dependency
is when a non-prime attribute is dependent on
another non-prime attribute.
Practice exercise to solidify understanding