Module Title: Databases & SQL Assignment Title: Case Study: Server database Example Module Leader: M. Nawaz Module Code: HSQ
A Taxi Company Database (Partial) – Text a Taxi and Vehicle Servicing
By: David Grylls F6106630 Date: 11/01/2008
Table of Contents Section 1. Introduction 2. Entity Relationship Diagram & Entity 3. Entities Registered Customer Customer Address Address Employee Staff Type Taxi Pickup Points Taxi Destination Journey Charges Tariff Rates Tariff Types Taxi Driver Vehicle Vehicles Service History Service Booking Vehicle Parts Parts Supplier 4. Microsoft SQL Server (Query Analyzer) Insert script example – Tariff Types Drop table Select, From, Where Count Insert Like Update Delete Order By Joining Tables Create Table Alter Table Drop Column Distinct Create index Drop Index In Not In 5. Linking MS SQL to MS Access 6. Detach & Attach MS SQL Server Database 7. Conclusion 8. Appendix & Reference
1. Introduction A database has been developed for a taxi hire company. The Taxi company uses a service called ‘Text a Taxi’ and the database has been developed for this service and the servicing of its vehicles only. The database will hold registered customer details, employee details, vehicle details, vehicle service details and supplier details. Initial Design When designing the initial data model I used databaseanswers.org for ideas of various models before designing final data model. The Taxi Service model was initially used and the certain aspects of the Car Service Centre were incorporated into Taxi Service model. See appendix for design. From the initial design it was necessary that several tables should be incorporated into one table as to avoid clutter and unnecessary tables. The Mechanic’s Taxi Drivers and Call handler’s tables were all removed and Employee table was created. The Frequently Visited Address & Regular Customers were also removed as this would not be appropriate for the ‘Text a Taxi’ service that this database is designed on. Internet Registration was also removed and replaced with Registered Customers as customers have to register details by phone to use this service. The internet registration service will available at some point in the future. The Journey and Charges table were also incorporated together as no need to have separate tables. The registered customer will be able to text a location where they would like to be picked up from and a taxi will be dispatched to the address held on the database for the specified location. The vehicle servicing aspect of the database will show which mechanic completed a service on the vehicle, what parts were used and who the supplier was for the parts. The Taxi Company will also be able to identify which driver was involved in a customer pick up, what address they were picked up from, the time of pick up and drop off and the journey cost and distance.
2. Entity Relationship Diagram (ERD) The ERD below shows all relevant tables used in the database. A customer who has registered details can simply text a location where they would like picking up from. The Taxi Company can then obtain the customers details and send the relevant taxi to the address held.
2. Entity Below I have attempted to illustrate all of the tables and relationships present im the Taxi Company Database. MS SQL was used to create the tables and produce the diagram below. Here you can see the relationships between the tables. (Please see database diagrams for a clearer copy).
3. Entities
Registered Customer Entity Registered Customer Diagram 1
Customer Address Entity Customer Address Diagram 2
Entity’s left Registered Customer Diagram 1, Customer Address Diagram 2 and overleaf Address Diagram 1 were created for customers who have currently registered with taxi company by phone and for customers who will be added in the future by integrating database to a Website. Once customers have registered, customers can then use the ‘text a taxi’ service. Customers can provide multiple addresses and by simply texting ‘home’, ‘work’, ‘friend’ ect…to the taxi company, a taxi is dispatched to the relevant address. .
Address Entity Address Diagram 1
Many customers may provide the same address as other customers, for example friends addresses, this can be done easily using the Address_id.
Employee Entity Employee Diagram 1
The entity in Employee Diagram 1 stores all current employee information.
Staff Type Entity Staff Type Diagram 1
Staff Type Diagram 1 stores the employee job title information. This should have been incorporated within the Employee Entity instead of creating an unnecessary table.
Taxi Pickup Points Entity Taxi Pickup Points Diagram 1
Taxi pickup points stores customer pick up time information
Taxi Destination Entity Taxi Destination Diagram 1
Taxi Destination stores all customer destination
drop off times.
Journey Charges Entity Journey Charges Diagram 1
The Journey Charges Entity holds all journey charges information, distance travelled, tariff rate and driver information.
Tariff Rates Entity Tariff Rates Diagram 1
The Tariff Rates entity contains vehicle information to determine a tariff amount.
Tariff Types Entity Tariff Types Diagram 1
The Tariff Types entity holds all tariff charges added to each journey when destination reached.
Taxi Driver Vehicle Entity Taxi Driver Vehicle Diagram 1
The Taxi Driver Vehicle entity store taxi driver and vehicle information.
Vehicles Entity Vehicles Diagram 1
Vehicles entity holds all vehicle information currently availableincluding, road tax, insurance, MOT and next service date information. Also which driver is currently assigned to which vehicle. Further vehicles can be added or removed when necessary.
Service History Entity Service History Diagram 1
Service History stores details of vehicles last service, including which mechanic undertook the last service.
Service Booking Entity Service Booking Diagram 1
Service Booking entity holds information about a vehicles next service, including date and time vehicle is booked in for and which mechanic is due to complete service.
Vehicle Parts Entity Vehicle Parts Diagram 1
Vehicle Parts entity stores the part number used in service of a vehicle.
Parts Entity Parts Diagram 1
Parts entity stores all parts information and stores supplier details for re-ordering.
Supplier Entity Supplier Diagram 1
Supplier entity holds all supplier’s used by taxi company.
4. Microsoft SQL Server (Query Analyzer) Code used to insert data – all other insert scripts can be found in the appendix
Tariff Types Table
Drop Table SQL code used to delete table not being used.
Select, From, Where
Tables – employee Condition – to select all mechanic’s working for Taxi Company
Count
Tables – Registered Customers Condition – To count the total number of customers currently registered with Taxi Company
Insert
Tables – Registered Customers Condition – Insert a new customer into the database
Like
Tables – Address Condition – Search for customers whose postcode contains ‘DL’
Update
Tables – Vehicles Condition – update vehicle ‘EX05 PYR’ detail, tax expiry date and insurance expiry dates
Delete
Table – Employees Condition – Delete employee whose employee id is ‘CH010’ and mobile number is ‘07767568995’
Order By
Table – Employees Condition – Search in employees detail, display results in order by surname’s.
Joining Tables
Table – Vehicles, Service_booking Condition – select fields from both tables and display results from both tables. In this example, all make Ford vehicles are displayed with the date if service.
Create Table
Table – Driver_Waiting_List Condition – create a new table Driver Waiting List Table for drivers seeking employment.
Alter Table
Table – Registered Customers Condition – ADD a new field in registered customers table, name this field ‘special requirements’ which will contain information about the customer i.e wheel chair vehicle required.
Drop Column
Table – Vehicles Condition - Drop column named vehicle condition from ‘vehicles’ table
Distinct
Table – Employees Condition – select and display all records of ‘staff type id’
Create index
Table – Driver_Waiting_List Condition – Create and set DW_no to be Primary Key of table
Drop Index
Table – Driver_Waiting_List Condition – Disable current Primary Key DW_no
In
Table – Address Condition – display address id’s for customers who live in Hartlepool
Not In
Table – Address Condition - display address id’s for customers who do not live in Hartlepool.
5. Link Taxi database from MS SQL to MS Access A new MS Access was selected and Project (existing data) selected
The server name is entered and name of database taxi selected.
All information is now available in MS Access.
Having now connected the tables to MS Access I am now able to develop the tables either in MS Access or in MS SQL. Any changes will be reflected in both platforms.
Using MS Access gives a quick and easy way to modify and insert records in to a database.
6. Detach & Attach the taxi MS SQL Database Select the database taxi
Select ok to detach
Locate the Taxi database which has now been detached and it can now be moved, copied, deleted etc..
To attach to another server/computer network the open MS SQL Server and then the following is completed
Select the Taxi mdf file.
Database to be attached are now shown, selecting OK will attach database to server.
The Taxi Database is now attached.
7. Conclusion When I had finished the ISA I realised that the ERD I had developed had many faults, I should have used auto increment ID's on tables (for id fields). This would have made it easier to manage and be more efficient. The Taxi service data model I had originally based my design on was overly simple and incorrect which caused many problems when I was completing the relationship and primary key constraints. Tables and contents were deleted and further tables added in order to correct the problems with the relationships. Due to these problems much of my time was spent trying to correct them problems that I was unable to complete more extensive SQL Server Code and create more structured queries. I also should have incorporated a more in depth database to fulfil all the requirements for a Taxi company, and could have also expanded on the tariff structure to include times and calendars to incorporate double / treble time on after-hours / bank holidays etc. I had also intended to create a website in order for a customer to register their details online, this however was not possible due to :
The version of MS SQL Server Management Studio Express I only able to install on my computer. & I do not have access to any web design software to be able to link the database to Macromedia
Dreamweaver.
It was also not possible to complete this task in the university labs.
8. Appendix & Reference Insert Scripts for all tables: Insert scripts\address.rtf Insert scripts\customer address.rtf Insert scripts\employees.rtf Insert scripts\journey charges.rtf Insert scripts\parts.rtf Insert scripts\registered customers.rtf Insert scripts\service booking.rtf Insert scripts\service history.rtf Insert scripts\staff type.rtf Insert scripts\suppliers.rtf Insert scripts\tariff rates.rtf Insert scripts\tariff types.rtf Insert scripts\taxi destination.rtf Insert scripts\taxi driver vehicle.rtf Insert scripts\taxi pickup points.rtf Insert scripts\vehicle parts.rtf Insert scripts\vehicles.rtf Websites used: http://www.databaseanswers.org/data_models/index.htm - used to identify possible data models http://www.databaseanswers.org/data_models/taxi_service/index.htm - used to get initial design of data model http://www.databaseanswers.org/data_models/car_svc_center/index.htm - partly used for data model
Data Models: Initial data model design HSQ Databases & SQL by Mansha Nawaz Introduction to SQL by Rick F.van der Lans SQL User Guides University of Teeside SCM