Professional Documents
Culture Documents
PES University
UE18CS252
Submitted By
Second normal form (2NF): It is a normal form used in database normalization. A relation
is in the second normal form if it fulfils the following two requirements: It is in first normal form
and every non-primary attribute is fully functionally dependent on the primary key.
Third normal form: A relation is in third normal form if it is in 2NF and no non-key attribute is
transitively dependent on the primary key.
Boyce–Codd normal form (or BCNF or 3.5NF): Is a normal form used in database
normalization. It is a slightly stronger version of the third normal form (3NF). If a relational
schema is in BCNF then all redundancy based on functional dependency has been removed
• Customer_Details Relation:
1. DL_number -> Fname, Mname, Lname, Phone_number, Email_id, Street, City, State,
Zipcode, Membership_id, Membership_type
2. Zipcode -> State,City
• Car Relation:
1. Registration_number -> Model, Make, Model_year, Car_category_name, Loc_id,
Mileage, Availability_flag
2. Model -> Make
• Car_Category Relation:
1. Category_name -> No_of_luggage, No_of_person, Cost_per_day,
Late_fee_per_hour
• Booking_Details Relation:
1. Booking_id -> From_dt_time, Ret_dt_time, Amount, Booking_status, Pickup_loc,
Drop_loc, Reg_num, DL_num, Ins_code, Act_ret_dt_time, Discount_code
• Billing_Details Relation:
1. Bill_id -> Bill_date, Bill_status, Discount_amt, Total_amt, Tax_amt, Booking_id,
Total_late_fee
• Discount_Details Relation:
1. Discount_code -> Discount_name,Expiry_date,Discount_percentage
2. Discount_name -> Discount_code ,Expiry_date,Discount_percentage
• Rental_Car_Insurance Relation:
1. Insurance_code -> Insurance_name,Coverage_type,Cost_per_day
2. Insurance_name -> Insurance_code ,Coverage_type,Cost_per_day
Functional dependencies that violated normalization rules:
• Customer_Details Relation:
1. DL_number -> Zipcode
2. Zipcode -> State, City
• Car Relation:
1. Registration_number -> Model_name
2. Model_name -> Make
• Location_Details Relation
1. Location_id -> Zipcode
2. Zipcode -> State, City
DDL
Create a database and tables.
DELIMITER $$
CREATE TRIGGER not_below_twenty
BEFORE INSERT ON CUSTOMER_DETAILS FOR EACH ROW
BEGIN
IF NEW.AGE < 20
THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Trigger executed you are too young to
rent cars. Sorry..... ';
END IF;
END;
$$
DELIMITER ;
Create an BEFORE UPGRADE trigger that will say that the discount cannot be
increased.
DELIMITER $$
CREATE TRIGGER no_discount_can_be_edited
BEFORE UPDATE ON BILLING_DETAILS FOR EACH ROW
BEGIN
IF NEW.DISCOUNT_AMOUNT > OLD.DISCOUNT_AMOUNT
THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Call from the Trigger. Discount once
stated in the bill can not be increased. ';
END IF;
END;
$$
DELIMITER ;
SQL Queries
SQL query showing the usage of right outer join to display mileage, model_name,
location_name and city from the tables location_details and car.
SELECT car.mileage, car.model_name, location_details.location_name,
location_details.city
FROM car
RIGHT OUTER JOIN location_details
ON car.loc_id = location_details.location_id;
SQL query showing the usage of left outer join to display the reg_num, amount and
discount_amount from the tables booking_details and billing_details.
SELECT booking_details.reg_num, booking_details.amount,
billing_details.discount_amount
FROM booking_details
LEFT OUTER JOIN billing_details
ON booking_details.booking_id = billing_details.booking_id;
SQL query showing the usage of correlated query to display booking_id, pickup_loc
and amount from the table booking_details.
SQL query showing the usage of correlated nested query to display bill_id and total
from the table billing_details.
SELECT bill_id,
SUM(discount_amount +tax_amount) total
FROM
billing_details
INNER JOIN
booking_details
USING (booking_id)
GROUP BY booking_id
HAVING SUM(discount_amount + tax_amount) > 20;
SQL query showing the usage of aggregate query to display category_name and
average cost per day from the table car_category.
SELECT category_name,
AVG(cost_per_day)
FROM car_category
GROUP BY category_name
ORDER BY category_name;
SQL query showing the usage of aggergated query to display category_name and
maximum late fee per hour from the table car_category.
Conclusion
During the course of this project, I learnt a lot of practices that go into creating a
database, rules to construct a good ER diagram, how to come up with relational
schema mapping for the ER diagram, deriving functional dependencies, how to
normalize the relational schema, how to store and manipulate the data stores in the
tables in the database, make queries about joins, correlated nested queries and
aggregated queries and make complex triggers.