Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

2) SQL Command

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);

b) Data Manipulation Language


i) Create
INSERT INTO Bags (BagID, Bags, Type, Design, PriceRM, Quantity, Amount)
VALUES (NULL, ' MINI SOFT TRUNK', 'shoulder bag', 'LV', '13500', '1', '10');

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;

ii) Logical Operator


SELECT Bags, type, design
FROM Bags
WHERE type = 'Hand Bag' OR type = 'Bagpack'

iii) Special Operator


SELECT * FROM Bags
WHERE Bags LIKE 'L%';

iv) Aggregate Functions


SELECT COUNT(BagID), Type
FROM Bags
GROUP BY Type;

3) The database should in Normalization


a) First Norm Normalization

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.

Here is out table below :

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.

b) Second Norm Normalization


For a table to be in the Second Normal Form,
 It should be in the First Normal form.
 And, it should not have Partial Dependency

Here is our table in the First Norm :

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.

This is Dependency and we also call it Functional Dependency.

Create another table for Design, which will have design_id and design_name fields


and design_id will be the primary key.

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:

Now we achieve second normal form.

c) Third Norm Normalization

A table is said to be in the Third Normal Form when,


 It is in the Second Normal form.
 And, it doesn't have Transitive Dependency.

So we add a new column in table price which is barcode.

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.

And new price table.

So now we achieve third norm.

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.

e) Fourth Norm Normalization

A table is said to be in the Fourth Normal Form when,


 It is in the Boyce-Codd Normal Form.
 And, it doesn't have Multi-Valued Dependency.

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:

You might also like