Thursday, December 5, 2019
Entity Relationship Diagram for Normalisation
Question: Discuss about the ERD for Normalization Functions. Answer: ERD: Normalization: First Normalization Form: Eliminating repeating groups VIPStatus (VIPStatusID, VIPStatusName, DiscountPtge) Company (CompanyID, CompanyName, Address, Phone, Fax, Email) Customer (CustomerID, FirstName, LastName, Address, City, State, CompanyID, Mobile, PostCode, Email, CustomerTypeName, FFDiscount, VIPStatusID) Staff (StaffID, StaffName, Address, Phone, Email, SupervisorID, CompanyID) Location (LocationID, LocationName, State, City, PostCode) TravelBooking (TravelID, DepartureDate, ArrivalDate, OverallTravelAmount, CustomerID, StaffID, CompanyID, NumAdult, NumChild, InvoiceDate, TravelPackageAmount, IsAmountPaid, TravelPackageID, Description, PackageAmount, DatePkgIssued, DatePkgExpired, DepartingDate, ReturnDate, AirlineID, AirlineName, DepartureLocationID, DestinationLocationID, FlightID, FlightName, DateOfDeparture, DateOfArrival, CabinClass, AirlineCharges, HotelID, HotelName, LocationID, Phone) Second Normalization Form: Eliminating redundant data VIPStatus (VIPStatusID, VIPStatusName, DiscountPtge) Company (CompanyID, CompanyName, Address, Phone, Fax, Email) Customer (CustomerID, FirstName, LastName, Address, City, State, CompanyID, Mobile, PostCode, Email, CustomerTypeName, FFDiscount, VIPStatusID) Staff (StaffID, StaffName, Address, Phone, Email, SupervisorID, CompanyID) Location (LocationID, LocationName, State, City, PostCode) Hotels (HotelID, HotelName, LocationID, Phone) TravelPackage (TravelPackageID, Description, PackageAmount, DatePkgIssued, DatePkgExpired, DepartingDate, ReturnDate) Airline (AirlineID, AirlineName, DepartureLocationID, DestinationLocationID, FlightID, FlightName, DateOfDeparture, DateOfArrival, CabinClass, AirlineCharges) TravelBooking (TravelID, DepartureDate, ArrivalDate, OverallTravelAmount, CustomerID, StaffID, CompanyID, NumAdult, NumChild, InvoiceDate, TravelPackageAmount, IsAmountPaid, TravelPackageID, AirlineID, HotelID) Third Normalization Form: Remove Transitive Dependency CustomerType (CustomerTypeID, CustomerTypeName) Company (CompanyID, CompanyName, Address, Phone, Fax, Email) Customer (CustomerID, FirstName, LastName, Address, City, State, CompanyID, Mobile, PostCode, Email, CustomerTypeID) Staff (StaffID, StaffName, Address, Phone, Email, SupervisorID, CompanyID) VIPStatus (VIPStatusID, VIPStatusName, DiscountPtge) VIP (CustomerID, VIPStatusID) FrequentFlyer (CustomerID, FFDiscount) Location (LocationID, LocationName, State, City, PostCode) Flight (FlightID, FlightName) Hotels (HotelID, HotelName, LocationID, Phone) TravelPackage (TravelPackageID, Description, PackageAmount, DatePkgIssued, DatePkgExpired, DepartingDate, ReturnDate) Airline (AirlineID, AirlineName, DepartureLocationID, DestinationLocationID, FlightID, DateOfDeparture, DateOfArrival, CabinClass, AirlineCharges) TravelBooking (TravelID, DepartureDate, ArrivalDate, OverallTravelAmount, CustomerID, StaffID, CompanyID, NumAdult, NumChild) TravellingDetails (TravelPackageID, AirlineID, TravelID) StayAt (HotelID, TravelID, TravelPackageID) Invoice (InvoiceID, InvoiceDate, TravelPackageAmount, IsAmountPaid, TravelID, CustomerID) Note: Primary Key - Underline Foreign Key - Italics Relational Schema: CustomerType (CustomerTypeID, CustomerTypeName) Primary Key (CustomerTypeID) Company (CompanyID, CompanyName, Address, Phone, Fax, Email) Primary Key (CompanyID) Customer (CustomerID, FirstName, LastName, Address, City, State, CompanyID, Mobile, PostCode, Email, CustomerTypeID) Primary Key (CustomerID), Foreign Key (CompanyID) References Company (CompanyID), Foreign Key (CustomerTypeID) References CustomerType (CustomerTypeID) Staff (StaffID, StaffName, Address, Phone, Email, SupervisorID, CompanyID) Primary Key (StaffID), Foreign Key (SupervisorID) References Staff (StaffID), Foreign Key (CompanyID) References Company (CompanyID) VIPStatus (VIPStatusID, VIPStatusName, DiscountPtge) Primary Key (VIPStatusID) VIP (CustomerID, VIPStatusID) Primary Key (CustomerID), Foreign Key (CustomerID) References Customer (CustomerID) Foreign Key (VIPStatusID) References VIPStatus (VIPStatusID) FrequentFlyer (CustomerID, FFDiscount) Primary Key (CustomerID), Foreign Key (CustomerID) References Customer (CustomerID) Location (LocationID, LocationName, State, City, PostCode) Primary Key (LocationID) Flight (FlightID, FlightName) Primary Key (FlightID) Hotels (HotelID, HotelName, LocationID, Phone) Primary Key (HotelID), Foreign Key (LocationID) References Location (LocationID) TravelPackage (TravelPackageID, Description, PackageAmount, DatePkgIssued, DatePkgExpired, DepartingDate, ReturnDate) Primary Key (TravelPackageID) Airline (AirlineID, AirlineName, DepartureLocationID, DestinationLocationID, FlightID, DateOfDeparture, DateOfArrival, CabinClass, AirlineCharges) Primary Key (RestaurantID), Foreign Key (DepartureLocationID) References Location (LocationID), Foreign Key (DestinationLocationID) References Location (LocationID), Foreign Key (FlightID) References Flight (FlightID) TravelBooking (TravelID, DepartureDate, ArrivalDate, OverallTravelAmount, CustomerID, StaffID, CompanyID, NumAdult, NumChild) Primary Key (TravelID), Foreign Key (CustomerID) References Customer (CustomerID), Foreign Key (StaffID) References Staff (StaffID), Foreign Key (CompanyID) References Company (CompanyID) TravellingDetails (TravelPackageID, AirlineID, TravelID) Primary Key (TravelPackageID, AirlineID, TravelID), Foreign Key (TravelPackageID) References TravelPackage (TravelPackageID), Foreign Key (AirlineID) References Airline (AirlineID), Foreign Key (TravelID) References TravelBooking (TravelID) StayAt (HotelID, TravelID, TravelPackageID) Primary Key (TravelPackageID, AirlineID, TravelID), Foreign Key (TravelPackageID) References TravelPackage (TravelPackageID), Foreign Key (HotelID) References Hotels (HotelID), Foreign Key (TravelID) References TravelBooking (TravelID) Invoice (InvoiceID, InvoiceDate, TravelPackageAmount, IsAmountPaid, TravelID, CustomerID) Primary Key (InvoiceID), Foreign Key (TravelID) References TravelBooking (TravelID), Foreign Key (CustomerID) References Customer (CustomerID) Database Schema: DROP TABLE IF EXISTS CustomerType ; CREATE TABLE IF NOT EXISTS CustomerType ( CustomerTypeID INT NOT NULL, CustomerTypeName VARCHAR(45) NOT NULL, PRIMARY KEY (CustomerTypeID)); -- ----------------------------------------------------- -- Table Company -- ----------------------------------------------------- DROP TABLE IF EXISTS Company ; CREATE TABLE IF NOT EXISTS Company ( CompanyID INT NOT NULL, CompanyName VARCHAR(45) NOT NULL, Address VARCHAR(60) NOT NULL, Phone VARCHAR(15) NOT NULL, Fax VARCHAR(15) NOT NULL, Email VARCHAR(45) NOT NULL, PRIMARY KEY (CompanyID)); -- ----------------------------------------------------- -- Table Customer -- ----------------------------------------------------- DROP TABLE IF EXISTS Customer ; CREATE TABLE IF NOT EXISTS Customer ( CustomerID INT NOT NULL, FirstName VARCHAR(25) NOT NULL, LastName VARCHAR(25) NOT NULL, Address VARCHAR(60) NOT NULL, City VARCHAR(30) NOT NULL, State VARCHAR(3) NOT NULL, Mobile VARCHAR(15) NOT NULL, PostCode INT NOT NULL, Email VARCHAR(45) NOT NULL, CustomerTypeID INT NOT NULL, CompanyID INT NOT NULL, PRIMARY KEY (CustomerID), INDEX fk_Customer_CustomerType_idx (CustomerTypeID ASC), INDEX fk_Customer_Company1_idx (CompanyID ASC), CONSTRAINT fk_Customer_CustomerType FOREIGN KEY (CustomerTypeID) REFERENCES CustomerType (CustomerTypeID) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT fk_Customer_Company1 FOREIGN KEY (CompanyID) REFERENCES Company (CompanyID) ON DELETE NO ACTION ON UPDATE NO ACTION); -- ----------------------------------------------------- -- Table Staff -- ----------------------------------------------------- DROP TABLE IF EXISTS Staff ; CREATE TABLE IF NOT EXISTS Staff ( StaffID INT NOT NULL, StaffName VARCHAR(45) NOT NULL, Address VARCHAR(60) NOT NULL, Phone VARCHAR(15) NOT NULL, Email VARCHAR(45) NOT NULL, CompanyID INT NOT NULL, SupervisorID INT NULL, PRIMARY KEY (StaffID), INDEX fk_Staff_Company1_idx (CompanyID ASC), INDEX fk_Staff_Staff1_idx (SupervisorID ASC), CONSTRAINT fk_Staff_Company1 FOREIGN KEY (CompanyID) REFERENCES Company (CompanyID) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT fk_Staff_Staff1 FOREIGN KEY (SupervisorID) REFERENCES Staff (StaffID) ON DELETE NO ACTION ON UPDATE NO ACTION); -- ----------------------------------------------------- -- Table VIPStatus -- ----------------------------------------------------- DROP TABLE IF EXISTS VIPStatus ; CREATE TABLE IF NOT EXISTS VIPStatus ( VIPStatusID INT NOT NULL, VIPStatusName VARCHAR(45) NOT NULL, DiscountPtge FLOAT NOT NULL, PRIMARY KEY (VIPStatusID)); -- ----------------------------------------------------- -- Table VIP -- ----------------------------------------------------- DROP TABLE IF EXISTS VIP ; CREATE TABLE IF NOT EXISTS VIP ( CustomerID INT NOT NULL, VIPStatusID INT NOT NULL, INDEX fk_VIP_Customer1_idx (CustomerID ASC), INDEX fk_VIP_VIPStatus1_idx (VIPStatusID ASC), PRIMARY KEY (CustomerID), CONSTRAINT fk_VIP_Customer1 FOREIGN KEY (CustomerID) REFERENCES Customer (CustomerID) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT fk_VIP_VIPStatus1 FOREIGN KEY (VIPStatusID) REFERENCES VIPStatus (VIPStatusID) ON DELETE NO ACTION ON UPDATE NO ACTION); -- ----------------------------------------------------- -- Table FrequentFlyer -- ----------------------------------------------------- DROP TABLE IF EXISTS FrequentFlyer ; CREATE TABLE IF NOT EXISTS FrequentFlyer ( CustomerID INT NOT NULL, FFDiscount FLOAT NOT NULL, INDEX fk_FrequentFlyer_Customer1_idx (CustomerID ASC), PRIMARY KEY (CustomerID), CONSTRAINT fk_FrequentFlyer_Customer1 FOREIGN KEY (CustomerID) REFERENCES Customer (CustomerID) ON DELETE NO ACTION ON UPDATE NO ACTION); -- ----------------------------------------------------- -- Table Location -- ----------------------------------------------------- DROP TABLE IF EXISTS Location ; CREATE TABLE IF NOT EXISTS Location ( LocationID INT NOT NULL, LocationName VARCHAR(45) NOT NULL, City VARCHAR(30) NOT NULL, State VARCHAR(3) NOT NULL, PostCode INT NOT NULL, PRIMARY KEY (LocationID)); -- ----------------------------------------------------- -- Table Flight -- ----------------------------------------------------- DROP TABLE IF EXISTS Flight ; CREATE TABLE IF NOT EXISTS Flight ( FlightID INT NOT NULL, FlightName VARCHAR(45) NOT NULL, PRIMARY KEY (FlightID)); -- ----------------------------------------------------- -- Table Hotels -- ----------------------------------------------------- DROP TABLE IF EXISTS Hotels ; CREATE TABLE IF NOT EXISTS Hotels ( HotelID INT NOT NULL, HotelName VARCHAR(45) NOT NULL, Phone VARCHAR(15) NOT NULL, Location_LocationID INT NOT NULL, PRIMARY KEY (HotelID), INDEX fk_Hotels_Location1_idx (Location_LocationID ASC), CONSTRAINT fk_Hotels_Location1 FOREIGN KEY (Location_LocationID) REFERENCES Location (LocationID) ON DELETE NO ACTION ON UPDATE NO ACTION); -- ----------------------------------------------------- -- Table TravelPackage -- ----------------------------------------------------- DROP TABLE IF EXISTS TravelPackage ; CREATE TABLE IF NOT EXISTS TravelPackage ( TravelPackageID INT NOT NULL, Description VARCHAR(60) NOT NULL, PackageAmount FLOAT NOT NULL, DatePkgIssued DATE NOT NULL, DatePkgExpired DATE NOT NULL, DepartingDate DATE NOT NULL, ReturnDate DATE NOT NULL, PRIMARY KEY (TravelPackageID)); -- ----------------------------------------------------- -- Table Airline -- ----------------------------------------------------- DROP TABLE IF EXISTS Airline ; CREATE TABLE IF NOT EXISTS Airline ( AirlineID INT NOT NULL, AirlineName VARCHAR(45) NOT NULL, DateOfDeparture DATE NOT NULL, DateOfArrival DATE NULL, CabinClass VARCHAR(30) NOT NULL, AirlineCharges FLOAT NOT NULL, DepartureLocationID INT NOT NULL, DestinationLocationID INT NOT NULL, FlightID INT NOT NULL, PRIMARY KEY (AirlineID), INDEX fk_Airline_Location1_idx (DepartureLocationID ASC), INDEX fk_Airline_Location2_idx (DestinationLocationID ASC), INDEX fk_Airline_Flight1_idx (FlightID ASC), CONSTRAINT fk_Airline_Location1 FOREIGN KEY (DepartureLocationID) REFERENCES Location (LocationID) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT fk_Airline_Location2 FOREIGN KEY (DestinationLocationID) REFERENCES Location (LocationID) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT fk_Airline_Flight1 FOREIGN KEY (FlightID) REFERENCES Flight (FlightID) ON DELETE NO ACTION ON UPDATE NO ACTION); -- ----------------------------------------------------- -- Table TravelBooking -- ----------------------------------------------------- DROP TABLE IF EXISTS TravelBooking ; CREATE TABLE IF NOT EXISTS TravelBooking ( TravelID INT NOT NULL, DepartureDate DATE NOT NULL, ArrivalDate DATE NOT NULL, OverallTravelAmount FLOAT NOT NULL, NumAdult INT NOT NULL, NumChild INT NOT NULL, CustomerID INT NOT NULL, StaffID INT NOT NULL, CompanyID INT NOT NULL, PRIMARY KEY (TravelID), INDEX fk_TravelBooking_Customer1_idx (CustomerID ASC), INDEX fk_TravelBooking_Staff1_idx (StaffID ASC), INDEX fk_TravelBooking_Company1_idx (CompanyID ASC), CONSTRAINT fk_TravelBooking_Customer1 FOREIGN KEY (CustomerID) REFERENCES Customer (CustomerID) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT fk_TravelBooking_Staff1 FOREIGN KEY (StaffID) REFERENCES Staff (StaffID) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT fk_TravelBooking_Company1 FOREIGN KEY (CompanyID) REFERENCES Company (CompanyID) ON DELETE NO ACTION ON UPDATE NO ACTION); -- ----------------------------------------------------- -- Table TravellingDetails -- ----------------------------------------------------- DROP TABLE IF EXISTS TravellingDetails ; CREATE TABLE IF NOT EXISTS TravellingDetails ( TravelID INT NOT NULL, TravelPackageID INT NOT NULL, AirlineID INT NOT NULL, INDEX fk_TravellingDetails_TravelBooking1_idx (TravelID ASC), INDEX fk_TravellingDetails_TravelPackage1_idx (TravelPackageID ASC), INDEX fk_TravellingDetails_Airline1_idx (AirlineID ASC), PRIMARY KEY (TravelID, TravelPackageID, AirlineID), CONSTRAINT fk_TravellingDetails_TravelBooking1 FOREIGN KEY (TravelID) REFERENCES TravelBooking (TravelID) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT fk_TravellingDetails_TravelPackage1 FOREIGN KEY (TravelPackageID) REFERENCES TravelPackage (TravelPackageID) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT fk_TravellingDetails_Airline1 FOREIGN KEY (AirlineID) REFERENCES Airline (AirlineID) ON DELETE NO ACTION ON UPDATE NO ACTION); -- ----------------------------------------------------- -- Table StayAt -- ----------------------------------------------------- DROP TABLE IF EXISTS StayAt ; CREATE TABLE IF NOT EXISTS StayAt ( HotelID INT NOT NULL, TravelID INT NOT NULL, TravelPackageID INT NOT NULL, INDEX fk_StayAt_Hotels1_idx (HotelID ASC), INDEX fk_StayAt_TravelBooking1_idx (TravelID ASC), INDEX fk_StayAt_TravelPackage1_idx (TravelPackageID ASC), PRIMARY KEY (HotelID, TravelID, TravelPackageID), CONSTRAINT fk_StayAt_Hotels1 FOREIGN KEY (HotelID) REFERENCES Hotels (HotelID) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT fk_StayAt_TravelBooking1 FOREIGN KEY (TravelID) REFERENCES TravelBooking (TravelID) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT fk_StayAt_TravelPackage1 FOREIGN KEY (TravelPackageID) REFERENCES TravelPackage (TravelPackageID) ON DELETE NO ACTION ON UPDATE NO ACTION); -- ----------------------------------------------------- -- Table Invoice -- ----------------------------------------------------- DROP TABLE IF EXISTS Invoice ; CREATE TABLE IF NOT EXISTS Invoice ( InvoiceID INT NOT NULL, InvoiceDate DATE NOT NULL, TravelPackageAmount FLOAT NOT NULL, IsAmountPaid VARCHAR(1) NOT NULL, TravelID INT NOT NULL, CustomerID INT NOT NULL, PRIMARY KEY (InvoiceID), INDEX fk_Invoice_TravelBooking1_idx (TravelID ASC), INDEX fk_Invoice_Customer1_idx (CustomerID ASC), CONSTRAINT fk_Invoice_TravelBooking1 FOREIGN KEY (TravelID) REFERENCES TravelBooking (TravelID) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT fk_Invoice_Customer1 FOREIGN KEY (CustomerID) REFERENCES Customer (CustomerID) ON DELETE NO ACTION ON UPDATE NO ACTION);
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.