Quantcast
Channel: Java, Database, Web And Mobile Apps - cs2it
Viewing all articles
Browse latest Browse all 191

Taxi on Demand full Database documentation with ERD

$
0
0

Introduction: 


You are part of a consultancy company that specialises in the provision of database applications. The Director of CabsOnDemand has recently approached your company to undertake a project to design and partially implement a database system for the company.

The CabsOnDemand Case Study:


A private taxi company called CabsOnDemand was established in London in 2012. Since then, the company has grown steadily and now has offices in most of the boroughs in North London. However, the company is now so large that more and more administrative staff are being employed to cope with the ever-increasing amount of paperwork. Furthermore, the communication and sharing of information within the company is poor. The Director of the company, Tom Sheridan feels that too many mistakes are being made and that the success of his company will be short-lived if he does not do something to remedy the situation. He knows that a database could help in part to solve the problem and has approached you to help in creating a database application to support the running of CabsOnDemand.

The Director has provided the following brief description of how CabsOnDemand operates.

Each office has a Manager, several taxi owners, drivers and administrative staff. The Manager is responsible for the day-to-day running of the office. An owner provides one or more taxis to CabsOnDemand and each taxi is allocated to a number of drivers for use. The majority of owners are also drivers themselves. For each taxi details such as Vehicle Registration Number, model, make, colour, capacity, currentMileage, DueDate for insurance are recorded.

For each staff, Staff Number, National Insurance Number, Address, Date of Birth, First Name, Last Name, Salary, Gender are recorded.

Each office is identified by a unique number, its location details, telephone and mobile numbers and email addresses are recorded.

The office issues contracts for clients and should record details of the contracts. Each contract is identified by a unique contract number, date at which contract was signed, its completion time, the total charge for contract and a maximum number of jobs allocated are recorded.

CabsOnDemand taxis are not available for hire by the public hailing a taxi in the street but must be requested by first phoning the company to attend a given address. This request is treated as a job and each job has to be identified uniquely; also all the details such as pick-up date, location, time, drop-off location, used mileages and the total chargeable amount should be recorded.

There are two kinds of clients, namely private and business. The business provided by private clients is on an ad-hoc basis. During the first booking, each client is given a unique identity and other details such as name, address information and contact details are collected.

However, the business provided by business clients is more formal and involves agreeing on a contract of work with the business. A contract stipulates the number of jobs that CabsOnDemand will undertake for a fixed fee hence, extra details such as the client's business type and email address are recorded too.

As described above, when a job comes into CabsOnDemand the name, phone number and contract number of the client is taken and then the pick-up date/time and pick-up/drop-off addresses are noted. Each job is allocated a unique jobID. The nearest driver to the pick-up address is called on his/her mobile and the job details are confirmed.

When a job is completed the driver should note the mileage covered or used and the charge made (for private clients only). If a job is not complete, the reason for the failed job should be a note.

ERD of Taxi on Demend



Create Table Queries

Tbl_office


CREATETABLE[dbo].[tbl_office](
       [office_id][int]NOTNULL,
       [location][varchar](50)NOTNULL,
       [phone_number][int]NOTNULL,
       [email][varchar](50)NOTNULL,
 CONSTRAINT[PK_tbl_office]PRIMARYKEYCLUSTERED
(
       [office_id]ASC
)WITH (PAD_INDEX=OFF,STATISTICS_NORECOMPUTE=OFF,IGNORE_DUP_KEY=OFF,ALLOW_ROW_LOCKS=ON,ALLOW_PAGE_LOCKS=ON)ON[PRIMARY]
)ON[PRIMARY]

Tbl_staff


CREATETABLE[dbo].[tbl_staff](
       [staff_id][int]NOTNULL,
       [office_id][int]NOTNULL,
       [national_insurance_number][varchar](50)NOTNULL,
       [address][varchar](50)NULL,
       [first_name][varchar](50)NOTNULL,
       [last_name][varchar](50)NOTNULL,
       [data_of_birth][date]NULL,
       [salary][int]NOTNULL,
       [gender][varchar](50)NOTNULL,
       [occupation][varchar](50)NOTNULL,
       [phone][int]NULL,
       foreignkey (office_id)referencestbl_office(office_id),
 CONSTRAINT[PK_tbl_staff]PRIMARYKEYCLUSTERED
(
       [staff_id]ASC
)WITH (PAD_INDEX=OFF,STATISTICS_NORECOMPUTE=OFF,IGNORE_DUP_KEY=OFF,ALLOW_ROW_LOCKS=ON,ALLOW_PAGE_LOCKS=ON)ON[PRIMARY]
)ON[PRIMARY]

TBL_owner


CREATETABLE[dbo].[tbl_owners](
       [owner_id][int]NOTNULL,
       [name][varchar](50)NULL,
       [email][varchar](50)NULL,
       [address][varchar](50)NULL,
       [phone][int]NULL,
 CONSTRAINT[PK_tbl_owners]PRIMARYKEYCLUSTERED
(
       [owner_id]ASC
)WITH (PAD_INDEX=OFF,STATISTICS_NORECOMPUTE=OFF,IGNORE_DUP_KEY=OFF,ALLOW_ROW_LOCKS=ON,ALLOW_PAGE_LOCKS=ON)ON[PRIMARY]
)ON[PRIMARY]

Tbl_driver


CREATETABLE[dbo].[tbl_drivers](
       [driver_id][int]NOTNULL,
       [name][varchar](50)NULL,
       [address][varchar](50)NULL,
       [phone_number][int]NULL,
 CONSTRAINT[PK_tbl_drivers]PRIMARYKEYCLUSTERED
(
       [driver_id]ASC
)WITH (PAD_INDEX=OFF,STATISTICS_NORECOMPUTE=OFF,IGNORE_DUP_KEY=OFF,ALLOW_ROW_LOCKS=ON,ALLOW_PAGE_LOCKS=ON)ON[PRIMARY]
)ON[PRIMARY]

Tbl_taxi


CREATETABLE[dbo].[tbl_taxi](
       [texi_id][int]NOTNULL,
       [owner_id][int]NOTNULL,
       [driver_id][int]NOTNULL,
       [registration_number][varchar](50)NULL,
       [current_mileage][int]NULL,
       [model][varchar](50)NULL,
       [location][varchar](50)NULL,
       [make][varchar](50)NULL,
       [color][varchar](50)NULL,
       [capacity][varchar](50)NULL,
       foreignkey (owner_id)referencestbl_owners(owner_id),
       foreignkey (driver_id)referencestbl_drivers(driver_id),
 CONSTRAINT[PK_tbl_taxi]PRIMARYKEYCLUSTERED
(
       [texi_id]ASC
)WITH (PAD_INDEX=OFF,STATISTICS_NORECOMPUTE=OFF,IGNORE_DUP_KEY=OFF,ALLOW_ROW_LOCKS=ON,ALLOW_PAGE_LOCKS=ON)ON[PRIMARY]
)ON[PRIMARY]

Tbl_contract


CREATETABLE[dbo].[tbl_contracts](
       [contract_id][int]NOTNULL,
       [charges][int]NOTNULL,
       [date][date]NOTNULL,
       [completion_time][time](7)NOTNULL,
       [status][varchar](50)NOTNULL,
       [reason][varchar](50)NOTNULL,
 CONSTRAINT[PK_tbl_contracts]PRIMARYKEYCLUSTERED
(
       [contract_id]ASC
)WITH (PAD_INDEX=OFF,STATISTICS_NORECOMPUTE=OFF,IGNORE_DUP_KEY=OFF,ALLOW_ROW_LOCKS=ON,ALLOW_PAGE_LOCKS=ON)ON[PRIMARY]
)ON[PRIMARY]

Tbl_client


CREATETABLE[dbo].[tbl_clients](
       [client_id][int]NOTNULL,
       [address][varchar](50)NULL,
       [contract_id][int]NULL,
       [email][varchar](50)NULL,
       [client_type][varchar](50)NULL,
       [business_type][varchar](50)NULL,
       [location][varchar](50)NULL,
       [name][varchar](50)NULL,
       foreignkey(contract_id)referencestbl_contracts(contract_id),
 CONSTRAINT[PK_tbl_clients]PRIMARYKEYCLUSTERED
(
       [client_id]ASC
)WITH (PAD_INDEX=OFF,STATISTICS_NORECOMPUTE=OFF,IGNORE_DUP_KEY=OFF,ALLOW_ROW_LOCKS=ON,ALLOW_PAGE_LOCKS=ON)ON[PRIMARY]
)ON[PRIMARY]

Tbl_jobs


CREATETABLE[dbo].[tbl_jobs](
       [job_id][int]NOTNULL,
       [used_mileage][int]NULL,
       [client_id][int]NULL,
       [charges][int]NULL,
       [pick_up_date][date]NULL,
       [pick_up_location][varchar](50)NULL,
       [drop_off_location][varchar](50)NULL,
       [time][time](7)NULL,
       [driver_id][int]NULL,
       foreignkey(client_id)referencestbl_clients(client_id),
 CONSTRAINT[PK_tbl_jobs]PRIMARYKEYCLUSTERED
(
       [job_id]ASC
)WITH (PAD_INDEX=OFF,STATISTICS_NORECOMPUTE=OFF,IGNORE_DUP_KEY=OFF,ALLOW_ROW_LOCKS=ON,ALLOW_PAGE_LOCKS=ON)ON[PRIMARY]

)ON[PRIMARY]

Insert Table Queries


Tbl_office


INSERTINTO[dbo].[tbl_office]
           ([office_id]
           ,[location]
           ,[phone_number]
           ,[email])
     VALUES
           (<office_id,int,>
           ,<location,varchar(50),>
           ,<phone_number,int,>
           ,<email,varchar(50),>)

Tbl_staff


INSERTINTO[dbo].[tbl_staff]
           ([staff_id]
           ,[office_id]
           ,[national_insurance_number]
           ,[address]
           ,[first_name]
           ,[last_name]
           ,[data_of_birth]
           ,[salary]
           ,[gender]
           ,[occupation]
           ,[phone])
     VALUES
           (<staff_id,int,>
           ,<office_id,int,>
           ,<national_insurance_number,varchar(50),>
           ,<address,varchar(50),>
           ,<first_name,varchar(50),>
           ,<last_name,varchar(50),>
           ,<data_of_birth,date,>
           ,<salary,int,>
           ,<gender,varchar(50),>
           ,<occupation,varchar(50),>
           ,<phone,int,>)

Tbl_owner


INSERTINTO[dbo].[tbl_office]
           ([office_id]
           ,[location]
           ,[phone_number]
           ,[email])
     VALUES
           (<office_id,int,>
           ,<location,varchar(50),>
           ,<phone_number,int,>
           ,<email,varchar(50),>)

Tbl_drivers


INSERTINTO[dbo].[tbl_drivers]
           ([driver_id]
           ,[name]
           ,[address]
           ,[phone_number])
     VALUES
           (<driver_id,int,>
           ,<name,varchar(50),>
           ,<address,varchar(50),>
           ,<phone_number,int,>)

Tbl_taxi


INSERTINTO[dbo].[tbl_taxi]
           ([texi_id]
           ,[owner_id]
           ,[driver_id]
           ,[registration_number]
           ,[current_mileage]
           ,[model]
           ,[location]
           ,[make]
           ,[color]
           ,[capacity])
     VALUES
           (<texi_id,int,>
           ,<owner_id,int,>
           ,<driver_id,int,>
           ,<registration_number,varchar(50),>
           ,<current_mileage,int,>
           ,<model,varchar(50),>
           ,<location,varchar(50),>
           ,<make,varchar(50),>
           ,<color,varchar(50),>
           ,<capacity,varchar(50),>)

Tbl_contract


INSERTINTO[dbo].[tbl_contracts]
           ([contract_id]
           ,[charges]
           ,[date]
           ,[completion_time]
           ,[status]
           ,[reason])
     VALUES
           (<contract_id,int,>
           ,<charges,int,>
           ,<date,date,>
           ,<completion_time,time(7),>
           ,<status,varchar(50),>
           ,<reason,varchar(50),>)

Tbl_clients


INSERTINTO[dbo].[tbl_clients]
           ([client_id]
           ,[address]
           ,[contract_id]
           ,[email]
           ,[client_type]
           ,[business_type]
           ,[location]
           ,[name])
     VALUES
           (<client_id,int,>
           ,<address,varchar(50),>
           ,<contract_id,int,>
           ,<email,varchar(50),>
           ,<client_type,varchar(50),>
           ,<business_type,varchar(50),>
           ,<location,varchar(50),>
           ,<name,varchar(50),>)

Tbl_Jobs


INSERTINTO[dbo].[tbl_jobs]
           ([job_id]
           ,[used_mileage]
           ,[client_id]
           ,[charges]
           ,[pick_up_date]
           ,[pick_up_location]
           ,[drop_off_location]
           ,[time]
           ,[driver_id])
     VALUES
           (<job_id,int,>
           ,<used_mileage,int,>
           ,<client_id,int,>
           ,<charges,int,>
           ,<pick_up_date,date,>
           ,<pick_up_location,varchar(50),>
           ,<drop_off_location,varchar(50),>
           ,<time,time(7),>

           ,<driver_id,int,>)

Report Queries


Report# 1:

The names and phone numbers of the Managers at each office.

Query:

selectfirst_nameas"First Name",last_nameas"Last Name",tbl_staff.phoneas"Contact",occupationas"Occupation"
fromtbl_staff,tbl_office
wheretbl_office.office_id=tbl_staff.office_idandtbl_staff.occupation='Manager'

Report# 2:

The names of all female drivers based in the Ealing or Islington office.

Query:

selecttbl_staff.first_nameas"First Name",tbl_staff.last_nameas"Last Name"
fromtbl_staff,tbl_office
wheretbl_staff.office_id=tbl_office.office_idandtbl_staff.gender='female'
and(tbl_office.location='Ealing'ortbl_office.location='Islington')

Report# 3:

The total number of staff at each office and their managers.

Query:

selectcount(tbl_staff.staff_id)as"Total Staff",tbl_staff.occupationas"Occupation"fromtbl_staff
groupbytbl_staff.occupation

Report# 4:

The details of all taxis at the Ealing office.

Query:

select*fromtbl_taxi
wheretbl_taxi.location='Ealing'

Report# 5:

The name and number of owners with more than one taxi.

Query:

selecttbl_owners.nameas"Name",tbl_owners.phoneas"Phone Number"fromtbl_owners
where 1<(selectCOUNT(tbl_taxi.texi_id)fromtbl_taxiwheretbl_owners.owner_id=tbl_taxi.owner_id)

Report# 6:

The full address of all business clients in Islington.

Query:

selecttbl_clients.addressas"Address"fromtbl_clients
wheretbl_clients.location='Islington'

Report# 7:

The details of the current contracts with business clients in Ealing.

Query:

selecttbl_contracts.contract_idas"ID",tbl_contracts.dateas"Date",
tbl_contracts.completion_timeas"Time",tbl_contracts.chargesas"Charges"
fromtbl_contracts,tbl_clients
wheretbl_contracts.contract_id=tbl_clients.contract_idandtbl_clients.location='Ealing'

Report# 8:

The total number of private clients in each borough.

Query:

selectcount(tbl_clients.client_id)as"Total number of clients"fromtbl_clients
wheretbl_clients.client_type='Private clients'

Report# 9:

The details of jobs undertaken by a driver on a given day.

Query:

selecttbl_jobs.job_idas"Job ID",tbl_jobs.pick_up_locationas"Pick up Location",
tbl_jobs.drop_off_locationas"Drop off Location",tbl_jobs.chargesas"Charges",
tbl_jobs.timeas"Time",tbl_contracts.dateas"Date"fromtbl_clients,tbl_contracts,tbl_jobs
wheretbl_clients.contract_id=tbl_contracts.contract_idandtbl_clients.client_id=tbl_jobs.client_id
anddate='11/18/2015'

Report# 10:

The names of private clients who hired a taxi in June 2014. 

Query:

selecttbl_clients.nameas"Name"fromtbl_clients,tbl_contracts
wheretbl_clients.contract_id=tbl_contracts.contract_id
andtbl_contracts.datebetween'06/01/2014'and'06/30/2014'


Download full documentataion with Visio file

 Download Now!







Viewing all articles
Browse latest Browse all 191

Trending Articles