itemized list template  · web viewharold pardue, professor of cis kent haley, is graduate student...

59
Itemized List Template Workbook Harold Pardue, Professor of CIS Kent Haley, IS Graduate student The objectives of this workbook are twofold: to assist the student in mastering the mechanics of ER modeling and to illustrate a modeling template that provides a good starting place as a solution to a class 1 of ER modeling problems. The Itemized List Template (ILT) abstracts a common pattern in ER modeling, namely, cases involving an itemized list. Examples of itemized lists abound in practice. An itemized list can be defined as any document or transaction that lists, enumerates, records, catalogs, specifies, or tallies a collection of items. An item can be anything from a product or service to an mp3 request in a peer-to-peer file swapping session. The vast majority of business transactions are “lists” which involve a customer or client engaging an agent of an organization (say a clerk or sales representative) to either purchase/receive a product or have a service rendered. These transactions are recorded as, for example, an invoice, order, back order, pick list, sales receipt, lease agreement, insurance claim, or bill of laden. Beyond contractual business transactions, much of what is stored in databases are lists; further, these lists tend to be associated with or related to other data in the database in a predictable way. Hence an advantage to learning the ILT is that it can provide an effective and efficient starting point for solving much larger and complex modeling problems. The ILT is depicted in Figure 1. 1 Thanks to Dr. Roy Daigle for encouraging me to look for solutions to classes of problems; it is a life lesson well worth learning. Page 1 of 59

Upload: ngothu

Post on 22-Mar-2019

213 views

Category:

Documents


0 download

TRANSCRIPT

Itemized List Template Workbook

Harold Pardue, Professor of CISKent Haley, IS Graduate student

The objectives of this workbook are twofold: to assist the student in mastering the mechanics of ER modeling and to illustrate a modeling template that provides a good starting place as a solution to a class1 of ER modeling problems.

The Itemized List Template (ILT) abstracts a common pattern in ER modeling, namely, cases involving an itemized list. Examples of itemized lists abound in practice. An itemized list can be defined as any document or transaction that lists, enumerates, records, catalogs, specifies, or tallies a collection of items. An item can be anything from a product or service to an mp3 request in a peer-to-peer file swapping session.

The vast majority of business transactions are “lists” which involve a customer or client engaging an agent of an organization (say a clerk or sales representative) to either purchase/receive a product or have a service rendered. These transactions are recorded as, for example, an invoice, order, back order, pick list, sales receipt, lease agreement, insurance claim, or bill of laden.

Beyond contractual business transactions, much of what is stored in databases are lists; further, these lists tend to be associated with or related to other data in the database in a predictable way. Hence an advantage to learning the ILT is that it can provide an effective and efficient starting point for solving much larger and complex modeling problems. The ILT is depicted in Figure 1.

At the center of the ILT are the List and ListItem entities. An itemized list is modeled as two entities: information about the List and the items being enumerated on the list, ListItem.

Note: if the list always contains one and only one instance of the list item, the ListItem entity can be omitted. Examples are provided in subsequent scenarios.

List will usually contain time-oriented information such as the time at which the list was created and last modified and when the product was shipped or service rendered. Additionally, the List entity typically includes (to list a few):

Summary or statistical information such as the number of items on the list or the total value of all items on the list

Client information specific to the list such as shipping or billing address The state of the list (active, deleted, archived, back-ordered, in-process…)

1 Thanks to Dr. Roy Daigle for encouraging me to look for solutions to classes of problems; it is a life lesson well worth learning.

Page 1 of 47

ListItem itemizes or enumerates the items associated with List. ListItem typically includes Item information specific to the current instance of the list such as extended price or quantity. ListItem sometimes includes a sequence number.

Item is the entity being itemized or enumerated on the list. In business transactions, this is typically a product or service.

Type classifies or categorizes Item. For example, in a database of musical titles, Type would be genre. In a business context, this could be a product catalog or menu hierarchy. It is often the case that we must model classification schemes or taxonomies associated with item entities.

Most lists involve two participants. One participant acts as a Client who orders, purchases, requests, or is associated with a list of items. A second participant acts as a Broker or agent for the organization, system, or ad hoc interaction. These roles are sometimes interchangeable and the same person. The broker works with the client to negotiate the terms and content of the list and represents the organization or system. Clients and brokers can be persons (customers, renters, sales associates, or clerks for example) or computing devices such as servers, routers, or ATMs.

The relationships and cardinality depicted in Figure 1 are representative only. See our textbook for Crow’s foot notation. I’ll elaborate on the ILT in class.

Page 2 of 47

Figure 1 Itemized List Template

What follows is a selection of database scenarios each with a blank ILT. The objective is to “fill-in” each of the templates using the information provided in the scenario. The notation used throughout this workbook is described in the next paragraph.

Words that give hints for potential entities are shown in bold, e.g. Officer. Words that give hints for potential relationships (i.e. 1:1, 1:M or M:N) are underlined, e.g. one, more, only, single, multiple etc. Words that give hints for optional or required entities and their cardinality are shown in italics, e.g. is, may, must, can, optional, could, at least one, no more than 10 etc. Verb phrase hints are indicated between braces { }.

Appendix I includes ERD solutions, SQL, and transactions.

Page 3 of 47

Scenario: WebDIY

You are responsible for designing a sales database for a web-based Do-It-Yourself (WebDIY) store that specializes in sales to contractors.

The DIY sells a wide range of products (tools, hardware, plumbing etc) via their web site (depending on the availability of shipping). Each contractor is assigned an account manager who completes sales.

The web site contains a hierarchical menu of product categories. For example, one branch in the menu hierarchy is:

Home: Building Products: Plumbing: Pipe & Fittings

The product category must be implemented in the database.

A sample (simplified) sales receipt is given below.

WebDIY“Brick-and-Mortar meets Click-and-Order”

Sale number: 45634 Account manager: 2345Contractor number: 3387 Date: December 11, 2005

ProductID Description Quantity Unit Price Ext Price23229 QT DRYDEX SPACKLI 100 $ 4.87 487.0095967 JH 1.88" X 60YED CLD 100 $ 6.44 644.0017705 1/16" TITANIUM DR 200 $ 2.96 296.0079562 WH IVY CASE 3" 100 $ 14.97 149.70

----------- Total $ 3220.70

Business Rules

1. A single sale {itemizes} many product saleitems. A sale must contain at least one product saleitem. A product saleitem must be associated with a sale.

2. A single account manager {completes} many sales. A sale must be completed by an account manager. An account manager is not required to complete a sale (could be a trainee or new hire).

3. A single contractor {requests} many sales. A sale must be for a contractor. A contractor is required to have at least one sale to be in the database.

Page 4 of 47

4. A single product {is sold as} a product saleitem many times. A product saleitem must be a product. A product is not required to be sold as a product saleitem (could be a new product that hasn’t sold yet).

5. A single product category {classifies} many products. A product must be classified as a single category. A category is not required to classify products (could be a new category for which no products are yet stocked).

6. A single product category {contains} many product subcategories. A product subcategory must be classified under a product category. A product category is not required to contain a product subcategory.

Given the information in the above scenario, fill in the ERD template shown on the next page. At the discretion of your instructor, you may work in small groups to discuss this scenario. However, do your best to work on your own to do the following:

1. Fill in the names of all entities on the template (inside grey box).2. Draw the relationships between the entities.3. Indicate on the template if the entity is required or optional.4. Fill in the appropriate verb phrase between each entity.5. Fill in the attributes for each entity directly mentioned or depicted in the scenario.6. List the identifiers for each entity.

Page 5 of 47

Scenario: WebDIY

Notes:

Page 6 of 47

Scenario: FEMA cabin assignments

You are responsible for designing a database to track the cabin assignments of hurricane Katrina evacuees on the cruise ship docked in Port of Mobile as part of FEMA’s Katrina relief program.

FEMA agents coordinate with a boarding officer (an employee of the cruise ship) to have an evacuee assigned to a cabin onboard the ship.

A cabin is assigned to an individual evacuee (the head of household in the case of a married couple or family).

If an evacuee is re-assigned to a new cabin, a new cabin assignment is generated. An evacuee occupies a cabin. An occupancy is for one 24 hour period. Consumables (food, personal items, or services) and incidents (medical emergencies, criminal, or civil disturbances) are associated with a specific day of occupancy. Assume that consumables and incidents are beyond the scope of the current analysis.

If an evacuee occupies a specific cabin for say 20 days, the cabin assignment will record (itemize) 20 occupancy records, one for each day.

Business Rules

1. A single cabin assignment {itemizes} many occupancy(ies). A cabin assignment must itemize at least one occupancy. An occupancy must be associated with a cabin assignment.

2. A cabin assignment includes the name of the head of household (evacuee), the number of persons occupying the cabin, and the cabin assignment request date.

3. An occupancy has a begin time and end time of occupancy and the maximum number of days a cabin can be occupied.

4. A single cruise ship boarding officer {grants} many FEMA cabin assignments. A cabin assignment must be granted by a boarding officer. A boarding officer is not required to grant a cabin assignment.

5. A single FEMA agent {requests} many cabin assignments. A cabin assignment must be requested by a FEMA agent. A FEMA agent is not required to request a cabin assignment.

6. A FEMA agent can be a supervisor to other FEMA agents. A single FEMA agent {supervises} many FEMA agents. A FEMA agent is not required to be supervised and a FEMA agent is not required to be a supervisor.

7. A single cruise ship cabin {is occupied as} an occupancy many times. An occupancy must be a cabin. A cabin is not required to be occupied as a FEMA occupancy (for example, cabins classified as crew quarters).

8. A single cabin type {classifies} many cabins. For example, a cabin can be classified as (standard inside, ocean view, balconied, or suite) A cabin

Page 7 of 47

must be classified under a single cabin type. A cabin type is not required to classify a cabin.

Given the information in the above scenario, fill in the ERD template shown on the next page. At the discretion of your instructor, you may work in small groups to discuss this scenario. However, do your best to work on your own to do the following:

1. Fill in the names of all entities on the template (inside grey box).2. Draw the relationships between the entities.3. Indicate on the template if the entity is required or optional.4. Fill in the appropriate verb phrase between each entity.5. Fill in the attributes for each entity directly mentioned or depicted in the scenario.6. List the identifiers for each entity.

Page 8 of 47

Scenario: FEMA cabin assignments

Notes:

Page 9 of 47

Scenario: Exam builder

You are responsible for designing a database for a web-based multiple-choice exam system for the school of CIS course assessment program. The effectiveness of each course in the CIS curriculum will be assessed each semester by administering a standardized multiple-choice exam designed specifically for each course.

Questions that appear on a course-specific assessment exam are classified by learning units. Learning units specify educational goals such as “to present architectures, topologies, and protocols of telecommunications.”

A sample exam containing two questions is depicted below.

Business Rules

1. A single exam {contains} many exam questions. An exam must contain at least one exam question. An exam question must be associated with an exam.

2. An exam question has a question stem, four choices (choiceA, choiceB, choiceC, and choiceD) and a correct answer. We’ll discuss this (A, B, C, D) structure later in the chapter on normalization. Question items are number sequentially.

3. A single instructor {creates} many exams. An exam must be created by an instructor. An instructor is not required to create an exam (an instructor could use an exam created by another instructor).

4. A single course {is assessed by} many exams (a different exam each semester perhaps). An exam must be created for a specific course. A course is not required to be assessed by an exam (some elective courses are not assessed).

5. A single question {appears as} an exam question many times. An exam question must be a question. A question is not required to appear as an exam question (could be a newly written question that hasn’t been put on an exam).

Page 10 of 47

6. A single leaning unit {classifies} many questions. A question must be classified under a single learning unit. A learning unit is not required to classify questions (we don’t teach all learning units in the curriculum).

Given the information in the above scenario, fill in the ERD template shown on the next page. At the discretion of your instructor, you may work in small groups to discuss this scenario. However, do your best to work on your own to do the following:

1. Fill in the names of all entities on the template (inside grey box).2. Draw the relationships between the entities.3. Indicate on the template if the entity is required or optional.4. Fill in the appropriate verb phrase between each entity.5. Fill in the attributes for each entity directly mentioned or depicted in the scenario.6. List the identifiers for each entity.

Page 11 of 47

Scenario: Exam builder

Notes:

Page 12 of 47

Scenario: Military Officer Promotion List

Your company has won a contract with the government to implement a database solution which produces a military officer promotion list. Once this solution has been tested and fully approved by your company, it will be used specifically by the U.S. Coast Guard to help produce promotion lists for the annual promotion cycle. During your interview with the Coast Guard contracting officer, you have determined that your solution needs to include the following business rules:

Business Rules:

1. Many officers are {listed on} a single promotion list. A promotion list may have an officer {listed} if there is an officer due for a promotion. However promotion lists are required for officers to be promoted.

2. It is required for an officer to {promote} many other officers. (relationship hint)3. A single promotion board is required to be {comprised of} many other officers.

However, an officer may be a {component} of a promotion board during his/her career.

4. Many promotion boards are required to {produce} a single promotion list at a time, and the promotion lists are required to be {produced} by a promotion board.

5. A single promotion list is required to {determine} many officer promotions, and promotions are required to be {determined} by one promotion list at a time.

6. In accordance with regulations, many promotions {determines} an officers rank one at a time during his or her career, and his or her rank is required to be {determined by} a promotion. That in return determines an officer’s rank they are being promoted to.

Given the information in the above scenario, fill in the ERD template shown on the next page. At the discretion of your instructor, you may work in small groups to discuss this scenario. However, do your best to work on your own to do the following:

1. Fill in the names of all entities on the template (inside grey box).2. Draw the relationships between the entities.3. Indicate on the template if the entity is required or optional.4. Fill in the appropriate verb phrase between each entity.5. Fill in the attributes for each entity directly mentioned or depicted in the scenario.6. List the identifiers for each entity.

Page 13 of 47

Scenario: Military Officer Promotion List

Notes:

Page 14 of 47

Scenario: Flight Itinerary

You are responsible for designing a database for a web-based flight itinerary builder. This web site allows customers to build a flight itinerary by selecting flights from a list of departures and arrivals for a specified date range.

The scope of this scenario exceeds the six entities of the ILT. Using the sample flight itinerary listed below, complete the ILT template and include additional entities as needed.

Page 15 of 47

Sample Flight Itinerary

Total price for this trip: $698.80  1  Review the flight details

Wed 22-Mar-06

Mobile (MOB)Depart 2:05 pm

 to  Atlanta (ATL)Arrive 4:25 pm Terminal S

302 mi(486 km)Duration: 1hr 20mn  Flight: 9086

Operated by: Delta

Economy/Coach Class, MDC MD80 Please check in with Delta. If checking in at a kiosk, use your name rather than confirmation number.

Atlanta (ATL)Depart 5:24 pm Terminal N

 to  Minneapolis (MSP)Arrive 7:15 pm Terminal L

908 mi(1,461 km)Duration: 2hr 51mn  Flight: 1275

Economy/Coach Class, Food For Purchase, Airbus A320, 70% on time

Minneapolis (MSP)Depart 9:35 pm Terminal L

 to  Duluth (DLH)Arrive 10:21 pm

144 mi(232 km)Duration: 0hr 46mn  Flight: 719

Economy/Coach Class, Airbus A320, 70% on time

Total distance: 1,354 mi (2,179 km) Total duration: 4hr 57mn (8hr 16mn with connections)

Wed 29-Mar-06

Duluth (DLH)Depart 5:20 am

 to  Minneapolis (MSP)Arrive 6:12 am Terminal L

144 mi(232 km)Duration: 0hr 52mn  Flight: 311

Economy/Coach Class, Airbus A319

Minneapolis (MSP)Depart 6:48 am Terminal L

 to  Memphis (MEM)Arrive 8:53 am

700 mi(1,127 km)Duration: 2hr 5mn  Flight: 448

Economy/Coach Class, MDC DC9-50, 70% on time

Memphis (MEM)Depart 9:30 am

 to  Mobile (MOB)Arrive 10:50 am

320 mi(515 km)Duration: 1hr 20mn  Flight: 5741

Operated by: Northwest Airlink

Total distance: 1,164 mi (1,873 km) Total duration: 4hr 17mn (5hr 30mn with connections)

Page 16 of 47

Business Rules

1. A single itinerary {lists} many flight choices. An itinerary must contain at least one flight choice. A flight choice must be listed on an itinerary.

2. A single member {builds} many itineraries. An itinerary is not required to be built by a member (anonymous web users can build an itinerary). A member is not required to build an itinerary.

3. A single webserver {retrieves} many itineraries. Assume this entity is beyond the scope of the current analysis.

4. A single flight {is chosen as} a flight choice many times. A flight choice must be a flight. A flight is not required to chosen as a flight choice.

5. A single airline {operates} many flights. A flight must be operated by a single airline. An airline is not required to operate a flight.

6. A single airport {services} many flights. An airport must service at least one flight. A flight is required to serviced by an airport.

Given the information in the above scenario, fill in the ERD template shown on the next page. At the discretion of your instructor, you may work in small groups to discuss this scenario. However, do your best to work on your own to do the following:

1. Fill in the names of all entities on the template (inside grey box).2. Draw the relationships between the entities.3. Indicate on the template if the entity is required or optional.4. Fill in the appropriate verb phrase between each entity.5. Fill in the attributes for each entity directly mentioned or depicted in the scenario.6. List the identifiers for each entity.

Page 17 of 47

Scenario: Flight Itinerary

Notes:

Page 18 of 47

Scenario: United Way Donation Designation

Assume you are hired to design a database to track United Way charity designations for our university. The current data input process is paper based using designation cards (see Figure 1). With this new database, donors will be able to login to a web-based application and designate their donation via a secure web form.

The pledge card (see first bold-faced line on form under title) is beyond the scope of this database and is not to be modeled. A pledge card documents the pledge amount and whether it will be a payroll deduction or one-time donation etc.

Line 1.Name is the donor designating the gift. A donor is an employee of the university. An employee does not have to submit a designation card (is optional), but a donor designation card must be for an employee. An employee can only submit one designation card per year. A designation card is for a particular year. An employee is identified by a Jnumber. Name and Jnumber (Jnumber is not shown on card) are required.

Company is the academic unit in which the donor works. Examples of academic units are {“School of CIS”, “Mitchell College of Business”, “Academic Computing”, “Allied Health”}. A donor’s designation card is associated with only one academic unit. An employee can, of course, be associated with multiple academic units, but the designation card is associated with only one academic unit. Company (academic unit) is required.

Designation cards are distributed and collected by a United Way representative from each academic unit. Administration requires that each academic unit have a representative. The representative is an employee from the respective academic unit. There is only one representative per academic unit and an employee can only represent one academic unit. An employee does not have to be a representative but a representative must be an employee from the respective academic unit. A representative, as an employee, can also submit a designation card. In this case, the representative is collecting his or her own designation card.

Line 2.A donor can designate that a portion of their United Way donation be directed to a specific agency. A donor can designate one or two agencies. A designation card must have at least one agency designation.

Dollar Amount The portion amount for an agency must be in whole dollars and greater than 25. A dollar amount is required.

Agency Name Agencies are identified by agency name. Agency name is required. An agency can be designated twice on the same designation card provided each designation is to a different agency code.

Page 19 of 47

Agency Code Designations are associated with a specific three digit agency code. Agency code is required and must match a valid agency code (see code numbers on reverse side of designation card). An agency can have multiple agency codes. An agency must have at least one agency code. An agency code is associated with a county in southwest Alabama. If an agency has only one agency code, the county is defaulted to “Mobile.”

Line 3.Signature A donor will “sign” the designation card by entering the last four digits of their social security number. Signature is required. The signature value must match the value for the employee making the designation.

Line 4.Keyperson Keyperson refers to the academic unit’s representative. Pledge card is outside the scope of this model.

Line 5.If the donor wishes to receive acknowledgement from the designation agencies, they must provide a mailing address. This address may or may not be the same as the address information officially recorded from the employee. Mailing address is required if the donor indicates acknowledgement is requested.

Page 20 of 47

Figure 1.

Page 21 of 47

Business Rules

Given the information in the above scenario, fill in the ERD template shown on the next page. At the discretion of your instructor, you may work in small groups to discuss this scenario. However, do your best to work on your own to do the following:

7. Fill in the names of all entities on the template (inside grey box).8. Draw the relationships between the entities.9. Indicate on the template if the entity is required or optional.10.Fill in the appropriate verb phrase between each entity.11.Fill in the attributes for each entity directly mentioned or depicted in the scenario.12.List the identifiers for each entity.

Page 22 of 47

Scenario: United Way Donation Designation

Page 23 of 47

APPENDIX I

Scenario: WebDIY

Page 24 of 47

SQL – DDL, DML

/*Itemized Template WorkbookCreated by Dr. Harold PardueHighlight each section of SQL and run separately to build database.Written using MS SQL Query Analyzer, SQL Server */

CREATE DATABASE WebDIY

Use WebDIY

--Create the 1 tables first then the many tables

CREATE TABLE tblContractor(ContractorID INT Identity(1,1) PRIMARY KEY,Name NVARCHAR(50) NOT NULL)

INSERT INTO tblContractor (Name) VALUES('Pervis Construction')INSERT INTO tblContractor (Name) VALUES('Mobile Pipe Company')

--Check insert statementsSELECT * FROM tblContractor

CREATE TABLE tblAccountManager(AccountManagerID INT Identity(1,1) PRIMARY KEY,Name NVARCHAR(50) NOT NULL)

INSERT INTO tblAccountManager (Name) VALUES('Joe Smith')INSERT INTO tblAccountManager (Name) VALUES('Jackie Tarvis')

--Check insert statementsSELECT * FROM tblAccountmanager

CREATE TABLE tblCategory(CategoryID INT Identity(1,1) PRIMARY KEY,Name NVARCHAR(50) NOT NULL,SubCategoryID INT NULL REFERENCES tblCategory(CategoryID) --Is a subcategory of )

--Highlight from BEGIN TRAN to COMMIT TRAN and run as a single transaction--@@Identity stores the most recently created autonumber which in this case--is the primary key value of tblCategory.BEGIN TRANINSERT INTO tblCategory (Name, SubCategoryID) VALUES('Home', NULL)INSERT INTO tblCategory (Name, SubCategoryID) VALUES('Building Products', @@Identity)INSERT INTO tblCategory (Name, SubCategoryID) VALUES('Plumbing', @@Identity)INSERT INTO tblCategory (Name, SubCategoryID) VALUES('Pipe & Fittings', @@Identity)COMMIT TRAN

--Check insert statementsSELECT * FROM tblCategory

CREATE TABLE tblProduct(ProductID INT Identity(1,1) PRIMARY KEY,Description NVARCHAR(50) NOT NULL,Price MONEY NOT NULL DEFAULT 0.0,CategoryID INT NOT NULL REFERENCES tblCategory(CategoryID))

--For convenience of illustration, put all products under category 1INSERT INTO tblProduct (Description, Price, CategoryID)

Page 25 of 47

VALUES ('QT DRYDEX SPACKLI',4.87,1)INSERT INTO tblProduct (Description, Price, CategoryID) VALUES ('JH 1.88" X 60YED CLD',6.44,1)INSERT INTO tblProduct (Description, Price, CategoryID) VALUES ('1/16" TITANIUM DR',2.96,1)INSERT INTO tblProduct (Description, Price, CategoryID) VALUES ('WH IVY CASE 3',14.97,1)

--Check insert statementsSELECT * FROM tblProduct

--Test referential integrity. Category 23 does not existINSERT INTO tblProduct (Description, Price, CategoryID) VALUES ('1 gal paint',23.00,23)

INSERT INTO tblProduct (Description, Price, CategoryID) VALUES ('1 gal paint',23.00,1)

CREATE TABLE tblSale(SaleID INT Identity(1,1) PRIMARY KEY,SaleDate DATETIME NOT NULL DEFAULT GETDATE(),SaleTotal MONEY NOT NULL DEFAULT 0.0,AccountManagerID INT NOT NULL REFERENCES tblAccountManager(AccountManagerID),ContractorID INT NOT NULL REFERENCES tblContractor(ContractorID) )

CREATE TABLE tblSaleItem(SaleItemID INT Identity(1,1) PRIMARY KEY,Quantity INT NOT NULL DEFAULT 0,UnitPrice MONEY NOT NULL DEFAULT 0.0,ExtendedPrice MONEY NOT NULL DEFAULT 0.0,SaleID INT NOT NULL REFERENCES tblSale(SaleID),ProductID INT NOT NULL REFERENCES tblProduct(ProductID))

--Highlight from BEGIN TRAN to COMMIT TRAN and run as a single transactionBEGIN TRAN DECLARE @ContractorID INT, @AccountManagerID INT, @ProductID INT, @SaleID INT

SET @ContractorID = (SELECT ContractorID FROM tblContractor WHERE Name='Pervis Construction') SET @AccountManagerID = (SELECT AccountManagerID FROM tblAccountManager WHERE Name='Jackie Tarvis')

INSERT INTO tblSale (SaleDate, SaleTotal, AccountManagerID, ContractorID) VALUES ('December 11, 2005', 3222.70, @AccountManagerID, @ContractorID)

--Retrieve the newly created primary key to insert as a foreign key in tblSaleItem SET @SaleID = @@Identity

--Retrieve primary key of product for current listitem --Insert new row in tblSaleItem SET @ProductID = (SELECT ProductID FROM tblProduct WHERE Description ='QT DRYDEX SPACKLI')

INSERT INTO tblSaleItem (Quantity, UnitPrice, ExtendedPrice, SaleID, ProductID) VALUES (100, 4.87, 487.00, @SaleID, @ProductID)

SET @ProductID = (SELECT ProductID FROM tblProduct WHERE Description ='JH 1.88" X 60YED CLD')

INSERT INTO tblSaleItem (Quantity, UnitPrice, ExtendedPrice, SaleID, ProductID) VALUES (100, 6.44, 644.00, @SaleID, @ProductID) SET @ProductID = (SELECT ProductID FROM tblProduct WHERE Description ='1/16" TITANIUM DR')

INSERT INTO tblSaleItem (Quantity, UnitPrice, ExtendedPrice, SaleID, ProductID) VALUES (200, 2.96, 296.00, @SaleID, @ProductID) SET @ProductID = (SELECT ProductID FROM tblProduct WHERE Description ='WH IVY CASE 3')

INSERT INTO tblSaleItem (Quantity, UnitPrice, ExtendedPrice, SaleID, ProductID) VALUES (100, 14.97, 149.70, @SaleID, @ProductID)

Page 26 of 47

COMMIT TRAN

--Test inserts

SELECT * FROM tblSaleSELECT * FROM tblSaleItem

SELECT tblSale.SaleID, tblSale.SaleDate, tblSale.SaleTotal, tblSale.AccountManagerID, tblSale.ContractorID, tblSaleItem.SaleItemID, tblSaleItem.Quantity, tblSaleItem.UnitPrice, tblSaleItem.ExtendedPrice, tblSaleItem.SaleID, tblSaleItem.ProductID, tblProduct.DescriptionFROM tblSale, tblSaleItem, tblProductWHERE tblSale.SaleID=tblSaleItem.SaleID AND tblSaleItem.ProductID=tblProduct.ProductID

--DROP DATABASE WebDIY

Page 27 of 47

Scenario: Flight Itinerary

Page 28 of 47

/*Itemized Template WorkbookCreated October 7, 2006 by Kent Haley (IS Graduate Student)Highlight each section of SQL and run separately to build database.Written using MS SQL Query Analyzer, SQL Server */--DROP DATABASE FlightItineraryCREATE DATABASE FlightItinerary

--DROP DATABASE FlightItinerary

Use FlightItinerary

--turn off row counting. This will eliminate the message "1 Row effected" that is displayed in SQL-- when data is inserted into a tableSET NOCOUNT ON

--STEP ONE: Create the 1 tables first --start from top 1 table and work down, then left to right

--1st 1 table/* NOTE: the standard naming convetion for a table when creating it in SQL is to preface the table with "tbl" e.g. tblName. Remember, an entity may not necissarily become a table. An entity only becomes a table when it is created in SQL. */

DROP TABLE tblMemberCREATE TABLE tblMember(MemberID INT Identity(1,1) PRIMARY KEY, --Designating "primary key" should always enforce uniqueness of primary key insertedMemberLastName NVARCHAR(50),-- UNIQUE,MemberFirstName NVARCHAR(50)CONSTRAINT IdxLastName UNIQUE (MemberLastName))

ALTER TABLE tblMemberADD CONSTRAINT IdxLastName UNIQUE (MemberLastName)

sp_help tblMember

--Drop Table tblMember

Page 29 of 47

INSERT INTO tblMember (MemberLastName, MemberFirstName) VALUES('Smith', 'John')

SELECT * FROM tblMember

CREATE UNIQUE CLUSTERED INDEX IdxLastName ON tblMember.MemberLastName

INSERT INTO tblMember (MemberID, MemberLastName, MemberFirstName) VALUES(2, 'Smith', 'John')

--insert values into tblMemberBEGIN TRAN

INSERT INTO tblMember (MemberLastName, MemberFirstName) VALUES('Smith', 'John') --INSERT INTO tblMember (MemberLastName, MemberFirstName) VALUES('Last', 'First') --INSERT INTO tblMember (MemberLastName, MemberFirstName) VALUES('Last', 'First')

IF @@ERROR <> 0

--display message RAISERROR ('There is a problem with data being inserted to tblMember.', 16, 1)

ELSE

PRINT ('tblMember Data iserted successfully!')

COMMIT TRAN

--delete values from tblMember--Delete FROM tblMember

--check values inserted into tblMember--SELECT * FROM tblMember

--check that primary key is unique--INSERT INTO tblMember (MemberID, MemberLastName, MemberFirstName) VALUES(1, 'Smith', 'John')

Page 30 of 47

--check is good, duplicate primary key not allowed

--2nd 1 tableCREATE TABLE tblWebServer(WebServerID INT Identity(1,1) PRIMARY KEY,WebServerIPAddress NVARCHAR (15))

--insert values into tblWebServerBEGIN

INSERT INTO tblWebServer (WebServerIPAddress) VALUES('192.168.111.12')

IF @@ERROR <> 0

--display message RAISERROR ('There is a problem with data being inserted to tblWebServer.', 16, 1)

ELSE

PRINT ('tblWebServer Data iserted successfully!')

END

--Check insert statements--SELECT * FROM tblWebServer

--DELETE FROM tblWebServer

--DROP TABLE tblWebServer

--create 3rd 1 tableCREATE TABLE tblAirport(AirportID INT Identity(1,1) PRIMARY KEY,AirportName NVARCHAR (20) NOT NULL,AirportDescription NVARCHAR (3) NOT NULL)

SELECT * FROM tblAirport

--insert values into tblAirportBEGIN

Page 31 of 47

INSERT INTO tblAirport (AirportName, AirportDescription) VALUES('Mobile', 'MOB') INSERT INTO tblAirport (AirportName, AirportDescription) VALUES('Atlanta', 'ATL') INSERT INTO tblAirport (AirportName, AirportDescription) VALUES('Minneapolis', 'MSP') INSERT INTO tblAirport (AirportName, AirportDescription) VALUES('Duluth', 'DLH') INSERT INTO tblAirport (AirportName, AirportDescription) VALUES('Memphis', 'MEM') IF @@ERROR <> 0

--display message RAISERROR ('There is a problem with data being inserted to tblAirport.', 16, 1)

ELSE

PRINT ('tblAirport Data iserted successfully!')

END --DROP TABLE tblAirport

--Check insert statements--SELECT * FROM tblAirport

--create 4th 1 table (in this case last 1 table)CREATE TABLE tblAirline(AirlineID INT Identity(1,1) PRIMARY KEY,AirlineName NVARCHAR (50) NOT NULL)

DELETE FROM tblAirline

DROP TABLE tblAirline

SELECT * FROM tblAirline

BEGIN

INSERT INTO tblAirline (AirlineName) VALUES('Northwest') INSERT INTO tblAirline (AirlineName) VALUES('Delta') INSERT INTO tblAirline (AirlineName) VALUES('TWA') INSERT INTO tblAirline (AirlineName) VALUES('United') INSERT INTO tblAirline (AirlineName) VALUES('Southwest')

Page 32 of 47

IF @@ERROR <> 0

--display message RAISERROR ('There is a problem with data being inserted to tblAirline.', 16, 1)

ELSE

PRINT ('tblAirline Data iserted successfully!')

END

--check data in all 1 tablesSelect * from tblMemberSelect * from tblWebServerSelect * from tblAirportSelect * from tblAirline

--STEP TWO: Create the many tables next. Save the intersection table (bridge table) for last

--start from top many table and work down, then left to right

/* NOTES: On this scenario, treat each day (departure day and return day) as a separate itinerary. e.g. You'll have a itinerary for your day of departure and another itinerary for your day of return.

The total duration of the flight can be calculated in a report (derived attribute)from tblFlight.DepartureTime and tblFlight.ArrivalTime. The total distance of each itinerary can be calculated in a report (derived attribute) from tblFlight.Distance_mi and tblFlight.Distance_km. You would also most likely calculate (derive an attibute) for the total cost of the trip based one each separate cost for the depature itinerary and return itinerary */ DROP TABLE tblItinerary--Create 1st many tableCREATE TABLE tblItinerary(ItineraryID INT Identity(1,1) PRIMARY KEY,MemberID INT NOT NULL REFERENCES tblMember (MemberID),WebServerID INT NOT NULL REFERENCES tblWebServer (WebServerID),ItineraryDate DATETIME,Cost MONEY

Page 33 of 47

CONSTRAINT constrUniqTranItinerar UNIQUE (MemberID, WebserverID, ItineraryDate))

sp_help tblItinerary

--DROP TABLE tblItinerary

--ALTER TABLE tblItinerary

--DELETE FROM tblItinerary

--insert values into tblItineraryBEGIN

--insert values for departure itinerary dated 22 March 06 INSERT INTO tblItinerary (MemberID, WebServerID, ItineraryDate, Cost) VALUES (1, 1, '2006-03-22', $349.00) --insert values for return itinerary dated 29 March 06 INSERT INTO tblItinerary (MemberID, WebServerID, ItineraryDate, Cost) VALUES (1, 1, '2006-03-29', $349.00)

IF @@ERROR <> 0

--display message RAISERROR ('There is a problem with data being inserted to tblItinerary.', 16, 1)

ELSE

PRINT ('tblItinerary Data iserted successfully!')

END

INSERT INTO tblItinerary (MemberID, WebServerID, ItineraryDate, Cost) VALUES (1, 1, '2006-03-22', $349.00)

SELECT * FROM tblItinerary

--Check insert statements--SELECT * FROM tblItinerary

--Test referential integrity with tblMember. MemberID 2 does not exist

Page 34 of 47

--INSERT INTO tblItinerary (MemberID, WebServerID, ItineraryDate, Cost) --VALUES (2, 1, '2006-03-22', 349.00)--Test OK

--Test referential integrity with tblWebServer. WebServerID 2 does not exist --INSERT INTO tblItinerary (MemberID, WebServerID, ItineraryDate, Cost) --VALUES (1, 2, '2006-03-22', 349.00)--Test OK

--SELECT * FROM tblItinerary

--create 2nd many tableCREATE TABLE tblFlight(FlightID INT Identity (1,1) PRIMARY KEY NOT NULL,DepAirportID INT REFERENCES tblAirport (AirportID), --NOTE: The tblAirport and tblAirline tables have already been created. Therefore,DepartureTime DATETIME, --the FK's (DepAirportID, ArrAirportID and AirlineID) will be able to reference theirDepartureComments NVARCHAR (100), --corresponding tables once tblFlight is created. ALWAYS pay attention to what orderArrAirportID INT REFERENCES tblAirport (AirportID), --you build your tables.ArrivalTime DATETIME,ArrivalComments NVARCHAR (100),Distance_mi INT,Distance_km INT,FlightNumber INT,OPComments NVARCHAR (100),EconCoachClass NVARCHAR (100),Notes NVARCHAR (100))

--DROP TABLE tblFlight

/* NOTE: Treat each seaparate leg of each itinerary as one flight. e.g. The leg from Mobile to Atlanta is one flight, the leg from Atlanta to Minneapolis in another flight and the leg from Minneapolis to Duluth is the last flight for itinerary 1 dated 22 March 06. */

--insert values into tblFlightBEGIN

--insert values for 1st flight of departure itinerary (Mobile to Atlanta)

Page 35 of 47

INSERT INTO tblFlight (DepAirportID, DepartureTime, DepartureComments, ArrAirportID, ArrivalTime, ArrivalComments, Distance_mi, Distance_km, FlightNumber, OPComments, EconCoachClass, Notes) VALUES (1, '2006-03-22 2:05 PM', NULL, 2, '2006-03-22 4:25 PM', 'Terminal S', 302, 486, 9086, 'Operated by: Delta', 'MDC MD80', 'Please check in with Delta. If checking in at a kiosk, use your name rather than confirmation number') --insert values for 2nd flight of departure itinerary (Atlanta to Minneapolis) INSERT INTO tblFlight (DepAirportID, DepartureTime, DepartureComments, ArrAirportID, ArrivalTime, ArrivalComments, Distance_mi, Distance_km, FlightNumber, OPComments, EconCoachClass, Notes) VALUES (2, '2006-03-22 5:24 PM', 'Terminal N', 3, '2006-03-22 7:15 PM', 'Terminal L', 908, 1461, 1275, NULL, 'Food For Purchase, Airbus A320, 70% on time', NULL) --insert values for 3rd flight of departure itinerary (Minneapolis to Duluth) INSERT INTO tblFlight (DepAirportID, DepartureTime, DepartureComments, ArrAirportID, ArrivalTime, ArrivalComments, Distance_mi, Distance_km, FlightNumber, OPComments, EconCoachClass, Notes) VALUES (3, '2006-03-22 9:35 PM', 'Terminal L', 4, '2006-03-22 10:21 PM', NULL, 144, 232, 719, NULL, 'Food For Purchase, Airbus A320, 70% on time', NULL)

--insert values for 1st flight of return itinerary (Duluth to Minneapolis) /*** VALUES GO HERE ***/

--insert values for 2nd flight of return itinerary (Minneapolis to Memphis)

/*** VALUES GO HERE ***/

--insert values for 3rd flight of return itinerary (Memphis to Mobile)

/*** VALUES GO HERE ***/

IF @@ERROR <> 0

--display message RAISERROR ('There is a problem with data being inserted to tblFlight.', 16, 1)

Page 36 of 47

ELSE

PRINT ('tblFlight Data iserted successfully!')

END

--DELETE --FROM tblFlight

--check values inserted--Select * from tblFlight

--Create intersection table lastCREATE TABLE tblFlightChoice(ItineraryID INT REFERENCES tblItinerary(ItineraryID),FlightID INT REFERENCES tblFlight(FlightID))

DROP TABLE tblFlightChoice

INSERT INTO tblFlightChoice (ItineraryID, FlightID) VALUES (3,1)INSERT INTO tblFlightChoice (ItineraryID, FlightID) VALUES (3,2)INSERT INTO tblFlightChoice (ItineraryID, FlightID) VALUES (3,3)INSERT INTO tblFlightChoice (ItineraryID, FlightID) VALUES (4,1)INSERT INTO tblFlightChoice (ItineraryID, FlightID) VALUES (4,2)INSERT INTO tblFlightChoice (ItineraryID, FlightID) VALUES (4,3)

SELECT * FROM tblFlightChoice

--Generate a report for depature info for first leg of 22 March 06 flight

/******** Report code goes here ********/

DROP DATABASE FlightItinerary

Page 37 of 47

Scenario: FEMA

Page 38 of 47

/*Itemized Template WorkbookCreated by Kent Haley (IS Graduate Student)Highlight each section of SQL and run separately to build database.Written using MS SQL Query Analyzer, SQL Server */

--DROP DATABASE FEMA

--CREATE DATABASE FEMA

--Use FEMA

--Create the 1 tables first--start from top 1 table and work down, then left to right

--1st 1 table/* NOTE: the standard naming convetion for a table when creating it in SQL is to preface the table with "tbl" e.g. tblName. Remember, an entity may not necissarily become a table. An entity only becomes a table when it is created in SQL. */

CREATE TABLE tblFemaAgent(FemaAgentID NVARCHAR (5) PRIMARY KEY, --NOTE: Chose to use alphanumeric PK to help distinguish betweenAgentLastName NVARCHAR(50) NOT NULL, --FEMA agent ID and boarding officer/agent ID. Designating "primary key" Supervisor NVARCHAR (5) REFERENCES tblFemaAgent (FemaAgentID) --should always enforce uniqueness of primary key inserted)

GO

--Drop Table tblFemaAgent

--turn off row counting. This will eliminate the message "1 Row effected" that is displayed in SQL-- when data is inserted into a tableSET NOCOUNT ON

--insert values into tbleFemaAgent

Page 39 of 47

BEGIN TRAN

INSERT INTO tblFemaAgent (FemaAgentID, AgentLastName, Supervisor) VALUES('FA001', 'Jones', NULL ) INSERT INTO tblFemaAgent (FemaAgentID, AgentLastName, Supervisor) VALUES('FA002', 'Williams', 'FA001' ) INSERT INTO tblFemaAgent (FemaAgentID, AgentLastName, Supervisor) VALUES('FA003', 'Adams', 'FA001')

IF @@ERROR <> 0

--display message RAISERROR ('There is a problem with data being inserted to tblFemaAgent.', 16, 1)

ELSE

PRINT ('tblFemaAgent Data iserted successfully!')

COMMIT TRAN

GO

--delete values from tblFemaAgent--Delete FROM tblFemaAgent

--check values inserted into tblFemaAgent--SELECT * FROM tblFemaAgent

--check that primary key is unique--INSERT INTO tblFemaAgent (FemaAgentID, AgentLastName) VALUES('FA001', 'Pardue')--check is good, duplicate primary key not allowed

--2nd 1 tableCREATE TABLE tblBoardingOfficer(BoardingOfficerID NVARCHAR (5) PRIMARY KEY, --NOTE: designating "primary key" should alwaysBoardingOfficerLastName NVARCHAR(50) NOT NULL --enforce uniqueness of primary key inserted)

GO

Page 40 of 47

--insert values into tblBoardingOfficerBEGIN

INSERT INTO tblBoardingOfficer (BoardingOfficerID, BoardingOfficerLastName) VALUES('BA001', 'Smith') INSERT INTO tblBoardingOfficer (BoardingOfficerID, BoardingOfficerLastName) VALUES('BA002', 'Cooper') INSERT INTO tblBoardingOfficer (BoardingOfficerID, BoardingOfficerLastName) VALUES('BA003', 'Johnson')

IF @@ERROR <> 0

--display message RAISERROR ('There is a problem with data being inserted to tblFemaAgent.', 16, 1)

ELSE

PRINT ('tblBoardingOfficer Data iserted successfully!')

END

GO

--Check insert statements--SELECT * FROM tblBoardingOfficer

--create 3rd (in this case, last) 1 table and begin designating FK's to many tablesCREATE TABLE tblCabinType(CabinTypeID INT Identity(1,1) PRIMARY KEY, --REFERENCES tblCabin,CabinDescription NVARCHAR(50) NOT NULL,)

GO

--insert values into tblCabinTypeBEGIN

INSERT INTO tblCabinType (CabinDescription) VALUES('Ocean View') INSERT INTO tblCabinType (CabinDescription) VALUES('Upper Deck') INSERT INTO tblCabinType (CabinDescription) VALUES('Bow Area') INSERT INTO tblCabinType (CabinDescription) VALUES('Stern Area') INSERT INTO tblCabinType (CabinDescription) VALUES('Handicap')

Page 41 of 47

IF @@ERROR <> 0

--display message RAISERROR ('There is a problem with data being inserted to tblFemaAgent.', 16, 1)

ELSE

PRINT ('tblCabinType Data iserted successfully!')

END GO

--drop tabl tblCabinType--DROP TABLE tblCabinType

--Check insert statements--SELECT * FROM tblCabinType

--Create 1st many table--start from top many table and work down, then left to right CREATE TABLE tblAssignment(AssignmentID INT Identity(1,1) PRIMARY KEY,HOH_LastName NVARCHAR (50) NOT NULL,HOH_FirstName NVARCHAR (50) NOT NULL,PartyNumber INT NOT NULL,BoardingOfficerID NVARCHAR (5) NOT NULL REFERENCES tblBoardingOfficer (BoardingOfficerID), --NOTE: FK must be same data type and length as table referencedFemaAgentID NVARCHAR (5) NOT NULL REFERENCES tblFemaAgent (FemaAgentID), --NOTE: FK must be same data type and length as table referencedRequestDate DATETIME)

GO

--drop tblAssignment--DROP tblAssignment

--alter table tblAssignemt--ALTER TABLE tblAssignment-- DROP COLUMN CabinNumber

Page 42 of 47

--delete values from tblAssignment--DELETE FROM tblAssignment

--insert values into tblAssignmentBEGIN

INSERT INTO tblAssignment (HOH_LastName, HOH_FirstName, PartyNumber, BoardingOfficerID, FemaAgentID, RequestDate) VALUES ('OCharley', 'Kevin', 4, 'BA001', 'FA001', '9-1-2006') INSERT INTO tblAssignment (HOH_LastName, HOH_FirstName, PartyNumber, BoardingOfficerID, FemaAgentID, RequestDate) VALUES ('Dailey', 'George', 2, 'BA001', 'FA002', '9-1-2006') INSERT INTO tblAssignment (HOH_LastName, HOH_FirstName, PartyNumber, BoardingOfficerID, FemaAgentID, RequestDate) VALUES ('Davis', 'Mike', 3, 'BA001', 'FA002', '9-1-2006') INSERT INTO tblAssignment (HOH_LastName, HOH_FirstName, PartyNumber, BoardingOfficerID, FemaAgentID, RequestDate) VALUES ('Thompson', 'Bart', 3, 'BA002', 'FA003', '9-1-2006') INSERT INTO tblAssignment (HOH_LastName, HOH_FirstName, PartyNumber, BoardingOfficerID, FemaAgentID, RequestDate) VALUES ('White', 'Dennis', 2, 'BA002', 'FA003', '9-1-2006') INSERT INTO tblAssignment (HOH_LastName, HOH_FirstName, PartyNumber, BoardingOfficerID, FemaAgentID, RequestDate) VALUES ('Morrison', 'Jackie', 3, 'BA003', 'FA001', '9-1-2006') INSERT INTO tblAssignment (HOH_LastName, HOH_FirstName, PartyNumber, BoardingOfficerID, FemaAgentID, RequestDate) VALUES ('Campbell', 'Devin', 3, 'BA003', 'FA002', '9-1-2006') IF @@ERROR <> 0

--display message RAISERROR ('There is a problem with data being inserted to tblFemaAgent.', 16, 1)

ELSE

PRINT ('tblCabinType Data iserted successfully!')

END

GO

--Check insert statements--SELECT * FROM tblAssignment

--Test referential integrity. Boarding Officer BA004 does not exist

Page 43 of 47

--INSERT INTO tblAssignment (OccupantLastName, OccupantFirstName, BoardingOfficerID, FemaAgentID) -- VALUES ('Sutherland', 'Jim', 'BA004', 'FA002')

--create 2nd many tableCREATE TABLE tblCabin --NOTE: must crate this many table second, and skip many to many table (bridge). tblCabin must be --created first in order for tblOccpancy to have tblCabin to reference.(CabinID NVARCHAR (5) PRIMARY KEY,CabinTypeID INT REFERENCES tblCabinType(CabinTypeID), --not CabinType must be same data type and length as in tblCabinTypeDateIn DATETIME,DateOut DATETIME)

GO

--insert values into tblCabinBEGIN

INSERT INTO tblCabin (CabinID, CabinTypeID, DateIn, DateOut) VALUES ('U076', 1, '9-6-2006', '9-10-2006') INSERT INTO tblCabin (CabinID, CabinTypeID, DateIn, DateOut) VALUES ('U036', 2, '9-6-2006', '9-10-2006') INSERT INTO tblCabin (CabinID, CabinTypeID, DateIn, DateOut) VALUES ('A024', 2, '9-6-2006', '9-10-2006') INSERT INTO tblCabin (CabinID, CabinTypeID, DateIn, DateOut) VALUES ('B016', 1, '9-6-2006', '9-10-2006') INSERT INTO tblCabin (CabinID, CabinTypeID, DateIn, DateOut) VALUES ('B048', 3, '9-6-2006', '9-10-2006') INSERT INTO tblCabin (CabinID, CabinTypeID, DateIn, DateOut) VALUES ('D315', 4, '9-6-2006', '9-10-2006') INSERT INTO tblCabin (CabinID, CabinTypeID, DateIn, DateOut) VALUES ('C212', 4, '9-6-2006', '9-10-2006')

IF @@ERROR <> 0

--display message RAISERROR ('There is a problem with data being inserted to tblFemaAgent.', 16, 1)

ELSE

PRINT ('tblCabinCabin Data iserted successfully!')

Page 44 of 47

END

GO

--DELETE --FROM tblCabin

--check values inserted--Select * from tblCabin

--create last many table tblOccupancyCREATE TABLE tblOccupancy(AssignmentID INT REFERENCES tblAssignment,CabinID NVARCHAR (5) REFERENCES tblCabin,LogDate DATETIME,Comments NVARCHAR (100))

GO

--drop table tblOccupancy--DROP TABLE tblOccupancy

--SELECT * FROM tblOccupancy

--SELECT * FROM tblAssignment

--insert values into tblOccpancyBEGIN

INSERT INTO tblOccupancy (AssignmentID, CabinID, LogDate, Comments) VALUES (1, 'U076', '9-6-2006', 'no comments') INSERT INTO tblOccupancy (AssignmentID, CabinID, LogDate, Comments) VALUES (1, 'U076', '9-7-2006', 'occupant request ambulance for family emergency') INSERT INTO tblOccupancy (AssignmentID, CabinID, LogDate, Comments) VALUES (1, 'U076', '9-8-2006', 'domestic disturbance') INSERT INTO tblOccupancy (AssignmentID, CabinID, LogDate, Comments) VALUES (2, 'U036', '9-6-2006', 'no comments') INSERT INTO tblOccupancy (AssignmentID, CabinID, LogDate, Comments) VALUES (2, 'U036', '9-7-2006', 'loud noises coming from cabin') INSERT INTO tblOccupancy (AssignmentID, CabinID, LogDate, Comments) VALUES (3, 'A024', '9-8-2006', 'no comments') INSERT INTO tblOccupancy (AssignmentID, CabinID, LogDate, Comments) VALUES (4, 'B016', '9-8-2006', 'no comments')

Page 45 of 47

INSERT INTO tblOccupancy (AssignmentID, CabinID, LogDate, Comments) VALUES (5, 'B048', '9-6-2006', 'requested early departure') INSERT INTO tblOccupancy (AssignmentID, CabinID, LogDate, Comments) VALUES (5, 'B048', '9-7-2006', 'departed cabin')

IF @@ERROR <> 0

--display message RAISERROR ('There is a problem with data being inserted to tblFemaAgent.', 16, 1)

ELSE

PRINT ('tblOccupancy Data iserted successfully!')

END

--check inserted values--SELECT * FROM tblOccupancy

/* SELECT tblAssignment.AssignmentID, tblFemaAgent.FemaAgentID, tblFemaAgent.Supervisor, tblBoardingOfficer.BoardingOfficerID, tblAssignment.HOH_LastName, tblAssignment.HOH_FirstName, tblAssignment.PartyNumber, tblAssignment.RequestDate, tblCabin.DateIn, tblCabin.DateOut, tblCabin.CabinID, tblCabinType.CabinTypeID, tblOccupancy.LogDate, tblOccupancy.CommentsFROM tblAssignment, tblFemaAgent, tblBoardingOfficer, tblCabin, tblOccupancy, tblCabinTypeWHERE tblAssignment.FemaAgentID = tblFemaAgent.FemaAgentID AND tblAssignment.BoardingOfficerID = tblBoardingOfficer.BoardingOfficerID AND tblAssignment.AssignmentID = tblOccupancy.AssignmentID AND tblOccupancy.CabinID = tblCabin.CabinID AND tblCabin.CabinTypeID = tblCabinType.CabinTypeID*/

--DROP DATABASE FEMA

Page 46 of 47

Scenario solutionsERD SOLUTIONSQL (DDL, DML)TRANSACTIONS (sprocs and views)

Page 47 of 47