0% found this document useful (0 votes)
26 views6 pages

CSC 1033 Project 1

The document outlines the SQL table definitions and data insertion commands for a project involving transportation data, including tables for Districts, Stops, Routes, Operators, and Drives. It also includes example SQL queries to retrieve specific information from these tables. Additionally, it discusses database normalization and potential misuse indicators in database management.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views6 pages

CSC 1033 Project 1

The document outlines the SQL table definitions and data insertion commands for a project involving transportation data, including tables for Districts, Stops, Routes, Operators, and Drives. It also includes example SQL queries to retrieve specific information from these tables. Additionally, it discusses database normalization and potential misuse indicators in database management.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

CSC 1033 project 1

1)

2)

Table SQL for table creation


name
District -- project1.Districts definition

CREATE TABLE `Districts` (


`Name` varchar(10) NOT NULL,
`Phone number` varchar(13) NOT NULL,
PRIMARY KEY (`Name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_general_ci;
Stop -- project1.Stops definition

CREATE TABLE `Stops` (


`ID` int(4) NOT NULL,
`Descriptor` varchar(20) NOT NULL,
`District` varchar(10) NOT NULL,
PRIMARY KEY (`ID`),
KEY `Stops_Districts_FK` (`District`),
CONSTRAINT `Stops_Districts_FK` FOREIGN KEY (`District`)
REFERENCES `Districts` (`Name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_general_ci;
Route -- project1.Routes definition

CREATE TABLE `Routes` (


`ID` varchar(4) NOT NULL,
`Start` int(4) NOT NULL,
`End` int(4) NOT NULL,
`Frequency` int(1) NOT NULL,
PRIMARY KEY (`ID`),
KEY `Routes_Stops_FK` (`Start`),
KEY `Routes_Stops_FK_1` (`End`),
CONSTRAINT `Routes_Stops_FK` FOREIGN KEY (`Start`)
REFERENCES `Stops` (`ID`),
CONSTRAINT `Routes_Stops_FK_1` FOREIGN KEY (`End`)
REFERENCES `Stops` (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_general_ci;
Operator -- project1.Operators definition

CREATE TABLE `Operators` (


`Name` varchar(20) NOT NULL,
`Address` varchar(50) NOT NULL,
`Email` varchar(40) NOT NULL,
`Phone number` varchar(13) NOT NULL,
PRIMARY KEY (`Name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_general_ci;
Drives -- project1.Drives definition

CREATE TABLE `Drives` (


`Route` varchar(4) NOT NULL,
`Operator` varchar(20) NOT NULL,
`Proportion` decimal(10,0) NOT NULL,
PRIMARY KEY (`Operator`,`Route`),
KEY `Drives_Routes_FK` (`Route`),
CONSTRAINT `Drives_Operators_FK` FOREIGN KEY (`Operator`)
REFERENCES `Operators` (`Name`) ON DELETE CASCADE ON
UPDATE CASCADE,
CONSTRAINT `Drives_Routes_FK` FOREIGN KEY (`Route`)
REFERENCES `Routes` (`ID`) ON DELETE CASCADE ON UPDATE
CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_general_ci;

Table SQL for data addition


name
Districts INSERT INTO Districts (`Name`, `Phone number`) VALUES
("Northern", "01670111222"),
("Central", "01912665494"),
("Southern", "01913776611");
Stops INSERT INTO Stops (`ID`, `Descriptor`, `District`) VALUES
(1015, "Quayside", "Northern"),
(1023, "Ferry terminal", "Northern"),
(1500, "City Centre", "Central"),
(5032, "Blyth Estate", "Northern"),
(5061, "Village green", "Southern"),
(5500, "Dudley Estate", "Northern"),
(6700, "Airport", "Northern"),
(7628, "Shopping Centre", "Southern"),
(8000, "Durham Estate", "Southern"),
(9015, "Railway Station", "Central"),
(9016, "Railway Station", "Central"),
(9022, "Park Gates", "Southern");
Routes INSERT INTO Routes (`ID`, `Frequency`, `Start`, `End`) VALUES
("1", 2, 9015, 9022),
("16", 6, 7628, 1500),
("16a", 2, 7628, 9022),
("21", 4, 1023, 1015),
("22", 1, 1023, 1500),
("24", 4, 8000, 1500),
("30", 4, 1015, 1500),
("38", 1, 5061, 1500),
("64", 6, 9015, 7628),
("66", 1, 5061, 7628),
("88", 2, 9016, 1015),
("100", 4, 6700, 1500),
("111", 4, 6700, 9016),
("308", 2, 1500, 5032),
("350", 1, 5500, 5500),
("351", 1, 5500, 5500);
Operators INSERT INTO Operators (`Name`, `Address`, `Phone number`,
`Email`) VALUES
("Venture Travel", "Venture House, Consett, DH8 8SV",
"01207222145", "[email protected]"),
("OK Travel", "Bondgate, Durham, DH2 2BC", "01913013012",
"[email protected]"),
("Lockeys", "The Garage, Durham, DH1 1AB", "01913401934",
"[email protected]"),
("Bond Brothers", "Coronation Terrace, Durham, DH2 3AG",
"01913331234", "[email protected]"),
("Diamond Buses", "Diamond Buildings, Newcastle, NE2 5JH",
"01912678937", "[email protected]"),
("Blue Belle", "Lane End Garage, Durham, DH3 8BD",
"01913669147", "[email protected]"),
("Stephensons", "North Road Depot, Durham, DH1 2CD",
"01913114384", "[email protected]"),
("Northumbria Motor", "Jesmond Garage, Newcastle, NE2 2EN",
"01912084929", "[email protected]"),
("Moor-Dale Coaches", "Dudley Road, Newcastle, NE23 2MD",
"01912553272", "[email protected]");
Drives INSERT INTO Drives (`Operator`, `Route`, `Proportion`) VALUES
("Venture Travel", "1", 100),
("Diamond Buses", "16", 100),
("Diamond Buses", "16a", 100),
("Bond Brothers", "21", 100),
("Bond Brothers", "22", 100),
("Lockeys", "24", 25),
("OK Travel", "24", 25),
("Blue Belle", "24", 25),
("Stephensons", "24", 25),
("Bond Brothers", "30", 100),
("Stephensons", "38", 100),
("Lockeys", "64", 100),
("Blue Belle", "66", 100),
("Venture Travel", "88", 100),
("OK Travel", "100", 100),
("Venture Travel", "111", 50),
("OK Travel", "111", 50),
("Northumbria Motor", "308", 100),
("Moor-Dale Coaches", "350", 100),
("Moor-Dale Coaches", "351", 100);

3A)
SELECT `Name`,`Email`
FROM `Operators`
ORDER BY 'Email' ASC
LIMIT 1;

B)
SELECT d.`Phone number`
FROM Districts AS d , Stops AS s, Routes AS r
WHERE r.ID = 22 AND (s.ID = r.`Start` OR s.ID = r.`End`) AND d.Name =
s.District;
C)
SELECT d.name, count(*)
FROM Districts AS d, Stops AS s
WHERE d.Name = s.District
GROUP BY s.District HAVING count(*) > 4;

d)
SELECT o.email
FROM Stops s
JOIN Routes r ON s.ID = r.`Start` OR s.ID = r.`End`
JOIN Drives d ON r.ID = d.Route
JOIN Operators o ON o.Name = d.Operator
WHERE s.`Descriptor` LIKE '%Estate'
ORDER BY o.Email ASC;
4a)
Both staff and check would contain atomic data with no transitive dependencies
and full key dependencies, therefore making it valid in 3NF
b)
Staff ID, Name and Phone number won’t be fully dependant on Check ID (the
primary key). This results in a partial dependency, violating 2NF.
c)
Check Information and Staff Information would store lists (divisible information),
violating 1NF.
5a)
Query frequency: if a singular device is requesting a significant number of
queries in a short timeframe, that may signify unfair usage
Current connections: if there are a significant number of simultaneous
connections, misuse may be implied, or even if there are just a lot of
connections, potential failure could be noted
b)
User query log: noting which users are attempting to use modification (update,
delete, etc) may indicate misuse if not from an expected user
Permissions changes: a sudden, unexpected change in a user’s permissions
implies misuse and subsequent unwanted use of the database
Connection frequency: if there are suddenly a large amount of simultaneous
connections, that implies an attempt at a DDOS

You might also like