Database Assignment
Database Assignment
a) Data definition
i) Create
CREATE TABLE Bags (
BagID int NOT NULL AUTO_INCREMENT,
Bags varchar(255),
Type varchar(255),
Design varchar(255),
PriceRM varchar(255),
Quantity varchar(255),
Amount varchar(255),
PRIMARY KEY (BagID)
);
ii) Drop
DROP TABLE Bags;
iii) Alter
ALTER TABLE Bags
ADD Materials varchar(255);
ii) Delete
DELETE FROM Bags WHERE BagID=1;
iii) Update
UPDATE Bags
SET Bags = 'Louis Vuitton'
WHERE BagID = 1;
iv) Join
SELECT Accessories. AccessoriesId, Accessories. Accessories, Accessories.type,
Keychains.Keychain
FROM Accessories
INNER JOIN Keychains ON Accessories. AccessoriesId=Keychains.Keychains_ID;
v) Select
SELECT Bags, Type FROM Bags;
c) Operator
i) Comparison Operator
SELECT * FROM Bags
WHERE PriceRM > 10000;
For a table to be in the First Normal Form, it should follow the following 4 rules:
It should only have single(atomic) valued attributes/columns.
Values stored in a column should be of the same domain
All the columns in a table should have unique names.
And the order in which data is stored, does not matter.
Although a few values are getting repeated but values for the type, design, quantity
and amount, column are now atomic for each record/row.
Using the First Normal Form, data redundancy increases, as there will be many
columns with same data in multiple rows but each row as a whole will be unique.
In this table, bag_id is the primary key and will be unique for every row, hence we
can use bag_id to fetch any row of data from this table.
Now we have a Bag table with bag information and another table Design for storing
design information.
Now we create another table Price, to store the price information in the respective
bag. We will also be saving quantity along with amount.
In the price table we are saving the bag_id to know which bag’s are these
and design_id to know for which design the price are for.
Together, bag_id + design_id forms a Candidate Key for this table, which can be
the Primary key. The Partial Dependency is where an attribute in a table depends on
only a part of the primary key and not on the whole key, it is quantity and amount.
To achieve second norm, we have to remove partial dependency.
The solution is to remove columns amount from Price table and add it to the Design
table. Hence, the Design table will become:
barcode is just another column in the price table. It is not a primary key or even a
part of the primary key, and quantity depends on it. This is Transitive Dependency
and we have to remove it to achieve Third Norm. Put the barcode and quantity in
new table called barcode.
New barcode table.
d) Boyce-Codd Normalization
Boyce and Codd Normal Form is a higher version of the Third Normal form. For a
table to be in BCNF, following conditions must be satisfied:
R must be in 3rd Normal Form
and, for each functional dependency ( X → Y ), X should be a super Key.
Now we have all table in third norm, and if we see the table, it is already satisfy the
BCNF. Hence there is no need to satisfy BCNF again.
The first rules for fourth normalization is it has to be in the BCNF. But since we
already satisfy the BCNF, so there is no need to make a Fourth Normalization.
Database diagram: