Beruflich Dokumente
Kultur Dokumente
BUS EXAMPLE
BUS EXAMPLE
The following guide shows how to convert an entity relationship diagram (ERD) for
BUS to a SQL database using SQL script. You will have experience ERDs in MS
Access. The ERD is the diagram produced via the relationship screen.
SCHEMA - PHYSICAL
CONSTRAINTS
Inserting Data
MODEL SOLUTIONS
Solution Exercise 1 Produce a BUS ERD.
Solution Exercise 2 Create the physical schema for BUS ERD.
Script file : BUS.schema.sql
Solution Exercise 3 Review constraints for primary and foreign keys.
Solution Exercise 4 Create the logical schemas for BUS ERD.
Mansha Nawaz
BUS EXAMPLE
Case Study 9:
Case Study 9: MS SQL SERVER 2005 Management Studio Create tables via SQL Script
BUS EXAMPLE
ER Modeling
Exercise 1 Produce a BUS ERD.
A small bus company keeps details of the starting place, destination, and fare for all
routes which it operates. Each route has a unique route number and is divided into a
number of stages. A stage is identified by the names of the bus stops that mark its
beginning and end. For example, route number 154 goes from Hartlepool-Greatham,
Greatham-Wolviston, Wolviston-Billingham, and Billingham-Norton. Each stage may
appear in a number of routes, and is given a different sequence number for each
route. For example, Greatham-Wolviston is stage 2 on route 154, stage 3 on route
178 Billingham-Sunderland, and stage 6 on route 105 Stockton-Hartlepool. The
distance in miles is kept for each stage. Each route is associated with a number of
scheduled departures, each of which is identified by a day of the week and a time.
The estimated arrival time at the destination is recorded for each departure. There
may be a number of departures, for different routes, leaving at the same time?on the
same day. For example, route 154 departs at 9.15 on Monday, 10.00 on Wednesday,
and at 9.30 and 15.00 on Saturday. Route 105 also departs at 9.30 on Saturday.
Once a week a particular bus is allocated to each departure scheduled for the
following week. The data on which bus is allocated to which departure is only kept for
one week , being removed when buses are allocated for the following week. Details
of the registration number and seating capacity of each bus are recorded. Every
route must consist of at least one stage, but details of a stage may be kept even if it
is not currently part of route. Details of the scheduled departures are recorded before
buses are allocated. Details of all buses are recorded even if they are not currently
allocated to any departures. Details of routes are to be recorded before departures
have been arranged.
TASKS
For the above case study:
a. Derive an Entity Relationship Diagram (ERD) showing the entities of interest
and associated attributes, relationships, dependency and indicate primary and
foreign keys
b. Implement the tables in MS SQL Server 2005 by draw the ERD in MS SQL
Server 2005
c. Populate the tables with the sample data.
d. Provide sample SQL code to demonstrate and understanding of DDL and DML
SQL statements.
You may decide to modify the data requirements or generate additional data attributes
to assist in your design of the database. Write down details of any assumptions you
have made that you feel are important.
You may decide to follow the ERDs in Answer Points.
Mansha Nawaz
BUS EXAMPLE
Case Study 9:
Case Study 9: MS SQL SERVER 2005 Management Studio Create tables via SQL Script
BUS EXAMPLE
SCHEMA - PHYSICAL
Exercise 2 Create the physical schema for BUS ERD.
SQL Server Physical Schema are the SQL commands required for Table
Definitions.
Create table bus
(reg_no char(7),
No_of_seats integer,
Constraint buskey primary key(reg_no));
These commands are loaded into the QA interface and executed to create the
tables for the ERDs.
Create a schema for the tables identified in the BUS ERD.
CONSTRAINTS
Exercise 3 Review the constraints for primary and foreign
keys.
Make sure the constraints for primary and foreign keys are
embedded correctly in the SQL code generated in Ex 2.
BUS EXAMPLE
Case Study 9:
Case Study 9: MS SQL SERVER 2005 Management Studio Create tables via SQL Script
BUS EXAMPLE
Inserting Data
Exercise 4 Inserting data to the BUS database
Using the INSERT command write an insert schema to load the BUS
database with sample data.
ACCESS - SQL
Exercise 5 Produce a MS Access and MS SQL Server project
based on this case study
MS SQL Server Project - linking MS SQL server (physical tables) to MS Access
workstation (logical views)
Mansha Nawaz
BUS EXAMPLE
Case Study 9:
MODEL SOLUTIONS
The following model and schema does not cover every aspect of the case study.
Travels_on_a
Bus
0.. *
Route
0.. *
PK is reg_no, route_no
Makes_a
Bus
1..1
Departure
1..*
PK is reg_no
0..*
Along_a
1..1
Route
PK is route_no
Consists_of
Route
0..*
1..*
Stages
Stage_on_a_route
0..*
Consists_of
0..*
Route
1..1
PK is route_no
Is_a
1..1
PK is stage_start, stage_end
Stage
ERD BUS.
Makes_a
Bus
1..1
Departure
1..*
0..*
Along_a
Consists_of
Stage_on_a_route
1..1
Route
0..*
1..1
0..*
Is_a
1..1
Stage
Bus (reg_no, no_of_seats)
Departure (reg_no, route_no, departure_time, day, est_arrival_time)
Route (Route_no, Route_start, Route_end)
Stage_on_a_route (stage_start, stage_end, route_no, sequence_no)
Stage (stage_start, stage_end, distance)