0% found this document useful (0 votes)
52 views11 pages

Name: Matthew Bridgeman K Number: K1019426: CI2240 (Database Systems) Assignment 2012/13

This document contains the tasks for a database systems assignment. It includes creating an entity relationship diagram, data dictionary, CREATE TABLE statements, screenshots of populated data tables, and queries. The tasks involve designing tables for a car rental database with entities like customers, vehicles, employees, licenses, bookings, and drug tests. Constraints like primary keys, foreign keys, checks and NOT NULL are used to validate the data.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views11 pages

Name: Matthew Bridgeman K Number: K1019426: CI2240 (Database Systems) Assignment 2012/13

This document contains the tasks for a database systems assignment. It includes creating an entity relationship diagram, data dictionary, CREATE TABLE statements, screenshots of populated data tables, and queries. The tasks involve designing tables for a car rental database with entities like customers, vehicles, employees, licenses, bookings, and drug tests. Constraints like primary keys, foreign keys, checks and NOT NULL are used to validate the data.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

CI2240 (Database Systems) Assignment 2012/13

Name: Matthew Bridgeman K Number: K1019426

1. I declare that the attached work is all my own, and that where I have quoted from, used or referred to the opinions, work or writings of others, these have been fully and clearly acknowledged. 2. I am aware of the consequences of late submission.

Task 1: Entity Relationship Diagram

Task 2: Data Dictionary


Table name Customer Attribute name Customer_ID Name Date_of_Birth Address_Line City County Post_Code Email_Address Contact_Number Booking_ID Vehicle_ID Driver1_ID Driver2_ID Customer_ID Booking_Date Rental_Start_Date Rental_End_Date Vehicle_ID Model Number_of_Vehicles Hourly_Rate Test_ID Driver_ID Test_Date Result Driver_ID Employee_ID License_ID Employee_ID Name Date_of_Birth Address_Line City County Post_Code Contact_Number National_Insurance_Number Annual_Salary Employee_Type License_ID License_Number Expiry_Date Penalty_Points Code Data type Number Varchar2 Date Varchar2 Varchar2 Varchar2 Varchar2 Varchar2 Varchar2 Number Number Number Number Number Date Date Date Number Varchar2 Number Number Number Number Date Char Number Number Number Number Varchar2 Date Varchar2 Varchar2 Varchar2 Varchar2 Varchar2 Varchar2 Number Varchar2 Number Number Date Number Varchar2 PK/FK PK Not null Not null
check date < 14-DEC2012

Constraints

Not null PK FK FK FK FK Not null

Booking

Vehicle

PK Not null Not null Not null PK FK Not null PK FK FK PK Not null Not null
check date < 14-DEC2012

Test

Driver

Employee

Not null Not null PK Not null Not null Not null

Drivers_Lice nse

Task 3: CREATE TABLE statements


create table Customer (customer_ID number(6) PRIMARY KEY, name varchar2(50) NOT NULL, date_of_birth date CHECK(date_of_birth < '14-DEC-2012'), address_line varchar2(50), city varchar2(50), county varchar2(50), post_code varchar2(8), email_address varchar2(50), contact_number varchar2(20) NOT NULL); create table Vehicle (vehicle_ID number(6) PRIMARY KEY, model varchar2(50) NOT NULL, number_of_vehicles number(3) NOT NULL, hourly_rate number(3) NOT NULL); create table Employee (employee_ID number(6) PRIMARY KEY, name varchar2(50) NOT NULL, date_of_birth date CHECK(date_of_birth < '14-DEC-2012') NOT NULL, address_line varchar2(50), city varchar2(50), county varchar2(50), post_code varchar2(8), contact_number varchar2(20) NOT NULL, national_insurance_number varchar(9) NOT NULL, annual_salary number(6), employee_type varchar(15)); create table Drivers_License (license_ID number(6) PRIMARY KEY, license_number number(8) NOT NULL, expiry_date date NOT NULL, penalty_points number(2), code varchar(4) NOT NULL); create table Driver (driver_ID number(6) PRIMARY KEY, employee_ID number(6) REFERENCES Employee(employee_ID), license_ID number(6) REFERENCES Drivers_License(license_ID)); create table Booking (booking_ID number(6) PRIMARY KEY, vehicle_ID number(6) REFERENCES Vehicle(vehicle_ID), driver1_ID number(6) REFERENCES Driver(driver_ID), driver2_ID number(6) REFERENCES Driver(driver_ID), customer_ID number(6) REFERENCES Customer(customer_ID), booking_date date NOT NULL, rental_start_date date, rental_end_date date); create table Test (test_ID number(6) PRIMARY KEY,

driver_ID number(6) REFERENCES Driver(driver_ID), test_date date NOT NULL, result char(1) check(result in ('Y','N')));

Task 4: Screenshot of populated data

Task 5: Discussion of constraints used


Throughout the tables I have added, I have used three types of constraints, they are: 1. A check constraint to make sure that the customers or employees date of birth isnt after todays date. The way I did this was by using todays exact date, as I was unable to use the SYSDATE function for some reason. The code I used can be seen below: date_of_birth date CHECK(date_of_birth < '14-DEC-2012'), 2. Another check constraint, but this time it is used to make sure only the values Y or N are used with thr drug test result. result char(1) check(result in ('Y','N'))); 3. The third and final constraint I used was a NOT NULL constraint, to make sure values had to be entered in those columns. An example of this is the customer name field, as can be seen below: name varchar2(50) NOT NULL,

Task 6 (i): Query 1


This first query is designed to show the customers name, the drivers name, what vehicle they have booked and when they booked it. select customer.name,employee.name,vehicle.model,booking.booking_date from customer,employee,vehicle,booking,driver where booking.customer_id = customer.customer_id and booking.driver1_id = driver.driver_id and driver.employee_id = employee.employee_id and booking.vehicle_id = vehicle.vehicle_id

Task 6 (ii): Query 2


The second query is designed to search for any employee with points on their license or any positive drug tests. It will then display their names, the amount of points they have and the results of their tests. select employee.name,drivers_license.penalty_points,test.result from employee,drivers_license,test,driver where employee.employee_id = driver.employee_id and test.driver_id = driver.driver_id and driver.license_id = drivers_license.license_id and (test.result = 'Y' or drivers_license.penalty_points > 0)

Task 6 (iii): Query 3


The final query is designed to search for any drivers that have been booked to drive with an expired license. It will then display the customer name, rental start date, driver name and the date their license had expired.
select customer.name,booking.rental_start_date,employee.name,drivers_license.expiry_date from customer,booking,employee,drivers_license,driver where booking.customer_id = customer.customer_id and booking.driver1_id = driver.driver_id and driver.employee_id = employee.employee_id and driver.license_id = drivers_license.license_id and drivers_license.expiry_date < booking.rental_start_date

You might also like