0% found this document useful (0 votes)
0 views

query_DB_Project

The document outlines a database design for a transportation system, detailing the structure of tables for various departments including Operations, HR, Fleet Maintenance, Customer Service, Sales & Marketing, Finance, and Safety. It includes SQL commands for creating tables such as Station, Route, Stop, Timetable, Driver, and Customer, along with data insertion examples. The design emphasizes relationships between entities through foreign keys and provides a foundation for managing transportation operations and customer interactions.

Uploaded by

JF Rahat
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

query_DB_Project

The document outlines a database design for a transportation system, detailing the structure of tables for various departments including Operations, HR, Fleet Maintenance, Customer Service, Sales & Marketing, Finance, and Safety. It includes SQL commands for creating tables such as Station, Route, Stop, Timetable, Driver, and Customer, along with data insertion examples. The design emphasizes relationships between entities through foreign keys and provides a foundation for managing transportation operations and customer interactions.

Uploaded by

JF Rahat
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Database Design

--Operation Department: Tables->Route,Timetable,Stop,sattion


--SQL

CREATE TABLE Station (


StationID NUMBER PRIMARY KEY,
Name VARCHAR2(20) NOT NULL
);

CREATE TABLE Route (


RouteID NUMBER PRIMARY KEY,
Name VARCHAR2(20) NOT NULL,
OriginID NUMBER NOT NULL,
DestinationID NUMBER NOT NULL,
CONSTRAINT FK_OriginID FOREIGN KEY (OriginID) REFERENCES Station(StationID),
CONSTRAINT FK_DestinationID FOREIGN KEY (DestinationID) REFERENCES
Station(StationID)
);

CREATE TABLE Stop (


StationID NUMBER,
RouteID NUMBER,
StopNumber NUMBER,
PRIMARY KEY (StationID, RouteID, StopNumber),
CONSTRAINT FK_StationID FOREIGN KEY (StationID) REFERENCES Station(StationID),
CONSTRAINT FK_RouteID FOREIGN KEY (RouteID) REFERENCES Route(RouteID)
);

CREATE TABLE Timetable (


TimetableID NUMBER PRIMARY KEY,
RouteID NUMBER NOT NULL,
BusID NUMBER NOT NULL,
DriverID NUMBER NOT NULL,
St1_Time TIMESTAMP,
St2_Time TIMESTAMP,
St3_Time TIMESTAMP,
St4_Time TIMESTAMP,
St5_Time TIMESTAMP,
St6_Time TIMESTAMP,
St7_Time TIMESTAMP,
CONSTRAINT FK_RouteID_Timetable FOREIGN KEY (RouteID) REFERENCES
Route(RouteID),
CONSTRAINT FK_BusID FOREIGN KEY (BusID) REFERENCES Bus(BusID),
CONSTRAINT FK_DriverID FOREIGN KEY (DriverID) REFERENCES Driver(DriverID)
);

--2. HR Dept: Tables: Driver,DriverSalary


--SQL

CREATE TABLE Driver (


DriverID NUMBER PRIMARY KEY,
Name VARCHAR2(30) NOT NULL
);

CREATE TABLE DriverSalary (


Year NUMBER NOT NULL,
Month VARCHAR2(3) NOT NULL,
DriverID NUMBER NOT NULL,
Hourly NUMBER(10, 2) NOT NULL,
HoursWorked NUMBER NOT NULL,
Salary NUMBER(10, 2) NOT NULL,
PRIMARY KEY (Year, Month, DriverID),
CONSTRAINT FK_SalaryDriverID FOREIGN KEY (DriverID) REFERENCES Driver(DriverID)
);

--3. Fleet Maintenance and Engineering: Tables: Bus,BusFleetManagement


--SQL
CREATE TABLE Bus (
BusID NUMBER PRIMARY KEY,
Make VARCHAR2(30) NOT NULL,
Model VARCHAR2(30) NOT NULL,
Year NUMBER NOT NULL
);

CREATE TABLE BusFleetManagement (


BusID NUMBER,
MaintenanceDate DATE,
PRIMARY KEY (BusID, MaintenanceDate),
CONSTRAINT FK_FleetBusID FOREIGN KEY (BusID) REFERENCES Bus(BusID)
);

--4. Customer Service Department: Customer, Customer History


--SQL
CREATE TABLE Customer (
CustomerID NUMBER PRIMARY KEY,
Name VARCHAR2(30) NOT NULL
);

CREATE TABLE CustomerHistory (


HistoryID NUMBER PRIMARY KEY,
CustomerID NUMBER NOT NULL,
Datetime TIMESTAMP NOT NULL,
EnterStationID NUMBER NOT NULL,
ExitStationID NUMBER NOT NULL,
Charges NUMBER(10, 2) NOT NULL,
Credits NUMBER(10, 2) NOT NULL,
Balance NUMBER(10, 2) NOT NULL,
CONSTRAINT FK_CustomerID FOREIGN KEY (CustomerID) REFERENCES
Customer(CustomerID),
CONSTRAINT FK_EnterStation FOREIGN KEY (EnterStationID) REFERENCES
Station(StationID),
CONSTRAINT FK_ExitStation FOREIGN KEY (ExitStationID) REFERENCES
Station(StationID)
);

--5.Sales & Marketing: use customer & custoimerHistory table for analysis

--6. Finanace & Accounting Dept: Tables-->DriverSalary,CustomerHistory


--7. Safety and Complaince Department: Tables-->Driver & BusfleetManagement

--Data Insertion:
-- Insert Stations
INSERT INTO Station VALUES
(1, 'Est'), (2, 'Meadow Park'), (3, 'Central Terminal'), (4, 'Downtown Square'),
(5, 'Lake View'), (6, 'River Reach'), (7, 'West Bridge');

-- Insert Routes
INSERT INTO Route VALUES
(1, 'Main', 1, 5), (2, 'Main', 5, 1), (3, 'River', 1, 7), (4, 'River', 7, 1);

-- Insert Stops
INSERT INTO Stop VALUES
(1, 1, 1), (2, 1, 2), (3, 1, 3);

-- Insert Buses
INSERT INTO Bus VALUES
(350001, 'Mitsubishi', 'Aero Ace', 2019),
(350002, 'Mitsubishi', 'Aero Star', 2021);

-- Insert Drivers
INSERT INTO Driver VALUES
(350001, 'Teddy Park'), (350002, 'Sophia Nguyen');

-- Insert Timetable
INSERT INTO Timetable VALUES
(1, 1, 350001, 350001, TO_TIMESTAMP('2024-01-01 08:00:00', 'YYYY-MM-DD
HH24:MI:SS'), NULL, NULL, NULL, NULL, NULL, NULL);

-- Insert Customers
INSERT INTO Customer VALUES
(1, 'Yuna Ukawa'), (2, 'Liam Rodriguez');

-- Insert Customer History


INSERT INTO CustomerHistory VALUES
(1, 1, TO_TIMESTAMP('2024-01-01 08:00:00', 'YYYY-MM-DD HH24:MI:SS'), 1, 2, 10.00,
0.00, 90.00);

-- Insert Salaries
INSERT INTO DriverSalary VALUES
(2024, 'Jan', 350001, 25.00, 160, 4000.00);

-- Insert Fleet Maintenance


INSERT INTO BusFleetManagement VALUES
(350001, TO_DATE('2024-01-01', 'YYYY-MM-DD'));

You might also like