oscaraaronmontecino.comoscaraaronmontecino.com/Documents/IS_DataWharehousing_Mining.docx  · Web...

25

Click here to load reader

Transcript of oscaraaronmontecino.comoscaraaronmontecino.com/Documents/IS_DataWharehousing_Mining.docx  · Web...

Page 1: oscaraaronmontecino.comoscaraaronmontecino.com/Documents/IS_DataWharehousing_Mining.docx  · Web viewMIS 430, Fall 2014: Mid-Term Exam. Name: Oscar Aaron . Montecino (Chavez) Total

MIS 430, Fall 2014: Mid-Term Exam

Name: Oscar Aaron Montecino (Chavez)

Total Points = 120

You must type your answers in the word file below. No handwritten answers allowedCopy-paste your

SQL Script after testing it on SQL Server. No untested scripts must be submitted for answer.

Copy-past your ER-Model from Visio (please use Vision 2010 or earlier)

NOTE: All questions must be done individually. No consultation, discussion is allowed with anyone within or outside of the class. Any books or materials (online or otherwise) used must be suitably referenced. No ad-verbatim reproduction from any source (including class notes/lecture slides) is allowed. You must explain in your

own words.

Honor Code will be strictly followed.

You must submit both electronic copy, and a print copy of the exam by no later than 5:00 p.m. October 18, 2014

The George Mason University Honor code applies to this exam. You are expected to turn in your own work.

I understand and will abide by these rules and the George Mason University Honor code. I pledge that I have not received assistance of any kind on this exam.

Signature: _______________________________________ Date: ________________________

Page 2: oscaraaronmontecino.comoscaraaronmontecino.com/Documents/IS_DataWharehousing_Mining.docx  · Web viewMIS 430, Fall 2014: Mid-Term Exam. Name: Oscar Aaron . Montecino (Chavez) Total

1. Below is partial representation of an implemented database, based on the summary description. The purpose of the description is to provide you with the context for the database above.The design is of a database to be used by a company that owns a number of car dealerships across multiple states. The database is for capturing the data surrounding sales and service of various vehicles. More specifically, the database tracks the following information:The company sells variety of vehicles (cars, trucks, SUVs, etc.) of different makes and models and would like to track the year, make, model, options for different vehicles as well as technical information such as dimensions. The company tracks information about all vehicles in their inventory (new or used) noting specifics about options available on these vehicles. Additionally, the company also tracks information about cars that are brought in for servicing, whether or not these vehicles were originally sold by them.

Customer: The company would like to store customer information mainly name, address, and other demographic information (gender, age, etc.) if possible. In their definition of "customer", the company includes everyone who has not only purchased a vehicle from them, but also those who have test driven cars, contacted dealership(s) inquiring about information, brought vehicles in for service, etc.

Vehicle Sales: As part of sales they would like to also record all pre-sales information (specifically test drives of vehicles) and final sale.

Service: The dealerships offers two types of servicing - routine servicing/maintenance such as oil change, tire rotations, etc. and repairs. For routine services, there is an existing price list for the different services that are available. For repairs, first a diagnosis is performed and an estimate provided to the customer indicating the different parts that are required and the cost of these parts. Along with that an estimate of labor cost is also provided. Once approved by the customer actual repairs are conducted and customer pays for these charges. There is an existing system which already contains the parts related information. You can assume that your design will connect to this system and will be able to obtain all parts related information using a unique identifier called Part-Number.

Available Options

Installed Options

Inventory DealerVehicle

Used New

TestDrives

Customer

Sales

Service

Customer Vehicle

Routine Repairs

The tables correspond to the Entities represented above. The fields of the tables correspond to the attributes of these entities, along with data types used and null policies that are implemented are as follows:

The name in caps is the implemented table name, and must be used EXACTLY in implementing The field/attribute names are spelled out fully. You must use the column names EXACTLY as given.

Page 3: oscaraaronmontecino.comoscaraaronmontecino.com/Documents/IS_DataWharehousing_Mining.docx  · Web viewMIS 430, Fall 2014: Mid-Term Exam. Name: Oscar Aaron . Montecino (Chavez) Total

CUST: Customer(customer number, last name, first name, street number, street line 1, street line 2, city, state, zip code, drivers license, date of birth)

customer number: char(8), not null, uniquelast name, first name: User-Defined Data type (UDDT) names, not null street number: char(5), not nullstreet line 1: User-Defined Data type (UDDT) streetnames, not nullstreet line 2: User-Defined Data type (UDDT) streetnames, null allowed city: User-Defined Data type (UDDT) citynames, not nullstate: User-Defined Data type (UDDT) statenames, not nullzip code: User-Defined Data type (UDDT) zipCodes, null alloweddrivers license: char(10), null allowed, uniquedate of birth: smalldatetime, null allowed

DEALER: Dealer(dealer number, dealer name, street number, street line 1, street line 2, city, state, zip code, open date)dealer number: char(4), not null, uniquedealer name: varchar(30), not null, uniquestreet number: char(5), not nullstreet line 1: User-Defined Data type (UDDT) streetnames, not nullstreet line 2: User-Defined Data type (UDDT) streetnames, null allowed city: User-Defined Data type (UDDT) citynames, not nullstate: User-Defined Data type (UDDT) statenames, not nullzip code: UDDT zipCodes, not null open date: smalldatetime, not null

VEHICLE: Vehicle(vehicle code, year, make, model, trim line, date model introduced, msrp)vehicle code: char(7), not null, uniqueyear: smalldatetime, not nullmake: varchar(15), not nullmodel: varchar(15), null allowedtrim line: varchar(4), null alloweddate model introduced: smalldatetime, not nullmsrp: smallmoney, not null

INVENTORY: Dealer’s Vehicle Inventory(inventory code, dealer number, vin number, new or used, date arrived at dealership, date available in stock, date sold, listed price, exterior color, interior color, vehicle code, available for sale)

Inventory code: char(7), not null, uniquedealer number: char(4), not nullvin number: char(17), not nullnew or used: char(1), not nulldate arrived at dealership: smalldatetime, not nulldate available in stock: smalldatetime, null alloweddate sold: smalldatetime, null allowedlisted price: smallmoney, not nullexterior color: varchar(10), not nullinterior color: varchar(10), not nullvehicle code: char(7), not nullavailable for sale: bit, not null

NEWVEH: New Vehicles(inventory code, msrp, invoice price, date shipped)inventory code: char(7), not null, uniquemsrp: smallmoney, not nullinvoice price: smallmoney, not nulldate shipped: smalldatetime, not null

USEDVEH: Used Vehicles(inventory code, purchase date, purchase price, mileage, blue book value, trade in flag)inventory code: char(7), not null, uniquepurchase date: smalldatetime, not nullpurchase price: smallmoney, not nullmileage: int, not null

Page 4: oscaraaronmontecino.comoscaraaronmontecino.com/Documents/IS_DataWharehousing_Mining.docx  · Web viewMIS 430, Fall 2014: Mid-Term Exam. Name: Oscar Aaron . Montecino (Chavez) Total

blue book value: smallmoney, not nulltrade in flag: bit, not null

TESTDRIVE: Customer test drive(test drive code, customer number, date of test drive, duration of test drive, inventory code)Test drive code: char(7), not null, uniqueCustomer number: char(8), not nullDate of test drive: smalldatetime, not nullDuration of test drive: decimal, null allowedInventory code: char(7), not null

SALES: Vehicle Sales(inventory code, customer number, sales price, sales date, tax amount, payment method)Inventory code: char(7), not nullCustomer number: char(8), not nullSales price: smallmoney, not nullSales date: smalldatetime, not nullTax amount: smallmoney, not nullPayment method: char(1), not null

AVAILOPTIONS: Available vehicle options(option code, option cost, option msrp, option description, vehicle code)Option code: char(4), not null, uniqueOption cost: smallmoney, not nullOption msrp: smallmoney, null allowedOption description: varchar(200), null allowedVehicle code: char(7), not null

INSTOPTIONS: Installed Options(inventory code, option code, dealer installed flag)Inventory code: char(7), not nullOption code: char(4), not nullDealer installed flag: bit, not null

CUSTVEH: Customer vehicle(customer number, vin number, vehicle code, first seen date)Customer number: char(8), not nullVin number: char(17), not nullVehicle code: char(7), not nullFirst seen date: smalldatetime, not null

SERVREC: Service Record(service record number, customer number, vin number, dealer number, type of service, date brought in, mileage, date service completed, date billed, total service cost)

Service record number: char(8), not null uniqueCustomer number: char(8), not nullVin number: char(17), not nulldealer number: char(4), not nulltype of service: char(1), not nulldate brought in: smalldatetime, not nullmileage: int, not nulldate service completed: smalldatetime, null alloweddate billed: smalldatetime, null allowedtotal service cost: smallmoney, null allowed

ROUTSERV: Routine Service(service record number, service type code, list price, discount)service record number: char(8), not null uniqueservice type code: char(3), not nulllist price: smallmoney, not nulldiscount: smallmoney, not null

REPSERV: Repair Service(service record number, parts cost, labor hours, labor cost)service record number: char(8), not null unqiueparts cost: smallmoney, not nulllabor hours: decimal, not null

Page 5: oscaraaronmontecino.comoscaraaronmontecino.com/Documents/IS_DataWharehousing_Mining.docx  · Web viewMIS 430, Fall 2014: Mid-Term Exam. Name: Oscar Aaron . Montecino (Chavez) Total

labor cost: smallmoney, not null

Based on the above given information answer the following questions.

a) Create the ER model using Visio, clearly identify all the data types in accordance with the above specifications. Identify the primary and foreign keys, create the relationships and mark all the cardinalities using crow’s foot notation on the ER diagram. [25]You are required to use the provided information regarding the tables, to complete the ER. That is -- show all the attributes, identify the primary keys, foreign keys, and cardinalities of the relationships.

You should not have to create additional tables, attributes, or relationships beyond those provided in partial representation of ER and the table specifications above. [Note: Copy-Paste the ER-Model in Word file before printing for submission. Separately, the visio file must be submitted

on BlackBoard]

b) Copy-paste the SQL from SQL Server into specific parts below. Do not copy-paste script that is un-tested.

Create a database named DLRDB-[Your Initials]. Write the necessary SQL for each, test it in SQL Server, then copy-paste the specific SQL Script below:

Script for setting use to Database named DLRDB-[YourInitials] [1]

Part1CREATE DATABASE DLRDB_OAM;

Part 2USE [DLRDB_OAM]GO

Create the different User-Defined Data Types (UDDTs) required for different tables [3]

Page 6: oscaraaronmontecino.comoscaraaronmontecino.com/Documents/IS_DataWharehousing_Mining.docx  · Web viewMIS 430, Fall 2014: Mid-Term Exam. Name: Oscar Aaron . Montecino (Chavez) Total

CREATE TYPE lastname_dtFROM char(15) NOT NULL;

CREATE TYPE firstname_dtFROM char(15) NOT NULL;

CREATE TYPE streetone_dtFROM char(50) NOT NULL;

CREATE TYPE streettwo_dtFROM char(50) NULL;

CREATE TYPE city_dtFROM char(25) NOT NULL;

CREATE TYPE state_dtFROM char(30) NOT NULL;

CREATE TYPE zip_dtFROM char(5) NULL;

Create all the tables with specified data types above and without any unique constraints, primary keys, or foreign keys defined. [5]

--BEGIN CREATING TABLES--CREATE TABLE CUSTOMER(

[Customer Number] char(8) NOT NULL,[Last Name] lastname_dt NOT NULL,[First Name] firstname_dt NOT NULL,[Street Number] char(5) NOT NULL,[Street Line One] streetone_dt NOT NULL,[Street Line Two] streettwo_dt NULL,City city_dt NOT NULL,State state_dt NOT NULL,[Zip Code] zip_dt NULL,[Driver License] char(10) NOT NULL,[Date of Birth] smalldatetime NOT NULL

);

CREATE TABLE DEALER( [Dealer Number] char(4) NOT NULL,[Dealer Name] varchar(30) NOT NULL,[Street Number] char(5) NOT NULL,[Street Line One] streetone_dt NOT NULL,[Street Line Two] streettwo_dt NULL,City city_dt NOT NULL,State state_dt NOT NULL,[Zip Code] zip_dt NOT NULL,[Open Date] smalldatetime NOT NULL

);

CREATE TABLE VEHICLE([Vehicle Code] char(7) NOT NULL,Year smalldatetime NOT NULL,Make varchar(15) NOT NULL,Model varchar(15) NULL,[Trim Line] varchar(4) NULL,[Date Model Introduced] smalldatetime NOT NULL,MSRP smallmoney NOT NULL

Page 7: oscaraaronmontecino.comoscaraaronmontecino.com/Documents/IS_DataWharehousing_Mining.docx  · Web viewMIS 430, Fall 2014: Mid-Term Exam. Name: Oscar Aaron . Montecino (Chavez) Total

);

CREATE TABLE INVENTORY([Inventory Code] char(7) NOT NULL,[Dealer Number] char(4) NOT NULL,[Vin Number] char(17) NOT NULL,[new or used] char(1) NOT NULL,[Date Arrived at Dealership] smalldatetime NOT NULL,[Date Available in Stock] smalldatetime NULL,[Date Sold] smalldatetime NULL,[Listed Price] smallmoney NOT NULL,[Exterior Color] varchar(10) NOT NULL,[Interior Color] varchar(10) NOT NULL,[Vehicle Code] char(7) NOT NULL,[Available for Sale] bit NOT NULL

);

CREATE TABLE NEWVEH([Inventory Code] char(7) NOT NULL,MSRP smallmoney NOT NULL,[Invoice Price] smallmoney NOT NULL,[Date Shipped] smalldatetime NOT NULL

);

CREATE TABLE USEDVEH([Inventory Code] char(7) NOT NULL,[Purchase Date] smalldatetime NOT NULL,[Purchase Price] smallmoney NOT NULL,Mileage int NOT NULL,[Blue Book Value] smallmoney NOT NULL,[Trade in Flag] bit NOT NULL

);

CREATE TABLE TESTDRIVE([Test Drive Code] char(7) NOT NULL,[Customer Number] char(8) NOT NULL,[Date of Test Drive] smalldatetime NOT NULL,[Duration of Test Drive] decimal NULL,[Inventory Code] char(7) NOT NULL

);

CREATE TABLE SALES([Inventory Code] char(7) NOT NULL,[Customer Number] char(8) NOT NULL,[Sales Price] smallmoney NOT NULL,[Sales Date] smalldatetime NOT NULL,[Tax Amount] smallmoney NOT NULL,[Payment Method] char(1) NOT NULL

);

CREATE TABLE AVAILOPTIONS([Option Code] char(4) NOT NULL,[Option Cost] smallmoney NOT NULL,[Option MSRP] smallmoney NULL,[Option Description] varchar(200) NULL,[Vehicle Code] char(7) NOT NULL

);

Page 8: oscaraaronmontecino.comoscaraaronmontecino.com/Documents/IS_DataWharehousing_Mining.docx  · Web viewMIS 430, Fall 2014: Mid-Term Exam. Name: Oscar Aaron . Montecino (Chavez) Total

CREATE TABLE INSTOPTIONS([Inventory Code] char(7) NOT NULL,[Option Code] char(4) NOT NULL,[Dealer Installed Flag] bit NOT NULL

);

CREATE TABLE CUSTVEH([Customer Number] char(8) NOT NULL,[Vin Number] char(17) NOT NULL,[Vehicle Code] char(7) NOT NULL,[First Seen Date] smalldatetime NOT NULL

);

CREATE TABLE SERVREC([Service Record Number] char(8) NOT NULL,[Customer Number] char(8) NOT NULL,[Vin Number] char(17) NOT NULL,[Dealer Number] char(4) NOT NULL,[Type of Service] char(1) NOT NULL,[Date Brought In] smalldatetime NOT NULL,Mileage int NOT NULL,[Date Service Completed] smalldatetime NULL,[Date Billed] smalldatetime NULL,[Total Service Cost] smallmoney NULL

);

CREATE TABLE ROUTSERV([Service Record Number] char(8) NOT NULL,[Service Type Code] char(3) NOT NULL,[List Price] smallmoney NOT NULL,Discount smallmoney NOT NULL

);

CREATE TABLE REPSERV([Service Record Number] char(8) NOT NULL,[Parts Cost] smallmoney NOT NULL,[Labor Hours] decimal NOT NULL,[Labor Cost] smallmoney NOT NULL

);

Alter the tables to create all the unique constraints. [3]

--BEGIN CREATING UNIQUE KEYS--ALTER TABLE [dbo].[CUSTOMER]ADD CONSTRAINT Customer_UQ UNIQUE ([Customer Number], [Driver License]);

ALTER TABLE [dbo].[DEALER]ADD CONSTRAINT Dealer_UQ UNIQUE ([Dealer Number], [Dealer Name]);

ALTER TABLE [dbo].[VEHICLE]ADD CONSTRAINT Vehicle_UQ UNIQUE ([Vehicle Code]);

ALTER TABLE [dbo].[INVENTORY]ADD CONSTRAINT Inventory_UQ UNIQUE ([Inventory Code]);

ALTER TABLE [dbo].[NEWVEH]ADD CONSTRAINT NewVeh_UQ UNIQUE ([Inventory Code]);

Page 9: oscaraaronmontecino.comoscaraaronmontecino.com/Documents/IS_DataWharehousing_Mining.docx  · Web viewMIS 430, Fall 2014: Mid-Term Exam. Name: Oscar Aaron . Montecino (Chavez) Total

ALTER TABLE [dbo].[USEDVEH]ADD CONSTRAINT UsedVeh_UQ UNIQUE ([Inventory Code]);

ALTER TABLE [dbo].[TESTDRIVE]ADD CONSTRAINT TestDrive_UQ UNIQUE ([Test Drive Code]);

ALTER TABLE [dbo].[AVAILOPTIONS]ADD CONSTRAINT AvailOptions_UQ UNIQUE ([Option Code]);

ALTER TABLE [dbo].[SERVREC]ADD CONSTRAINT ServRec_UQ UNIQUE ([Service Record Number]);

ALTER TABLE [dbo].[ROUTSERV]ADD CONSTRAINT RoutServ_UQ UNIQUE ([Service Record Number]);

ALTER TABLE [dbo].[REPSERV]ADD CONSTRAINT RepServ_UQ UNIQUE ([Service Record Number]);

Alter the tables to create all the primary keys [5]

--BEGIN CREATING PRIMARY KEYS--ALTER TABLE [dbo].[CUTOMER] ADD CONSTRAINT [Customer_PK] PRIMARY KEY CLUSTERED ([Customer Number])GO

ALTER TABLE [dbo].[DEALER] ADD CONSTRAINT [Dealer_PK] PRIMARY KEY CLUSTERED ([Dealer Number])GO

ALTER TABLE [dbo].[VEHICLE] ADD CONSTRAINT [Vehicle_PK] PRIMARY KEY CLUSTERED ([Vehicle Code])GO

ALTER TABLE [dbo].[INVENTORY] ADD CONSTRAINT [Inventory_PK] PRIMARY KEY CLUSTERED ([Inventory Code])GO

ALTER TABLE [dbo].[NEWVEH] ADD CONSTRAINT [NewVeh_PK] PRIMARY KEY CLUSTERED ([Inventory Code], MSRP)GO

ALTER TABLE [dbo].[USEDVEH] ADD CONSTRAINT [UsedVeh_PK] PRIMARY KEY CLUSTERED ([Inventory Code], [Purchase Date])GO

ALTER TABLE [dbo].[TESTDRIVE] ADD CONSTRAINT [TestDrive_PK] PRIMARY KEY CLUSTERED ([Test Drive Code])GO

ALTER TABLE [dbo].[SALES] ADD CONSTRAINT [Sales_PK] PRIMARY KEY CLUSTERED ([Inventory Code], [Customer Number])GO

ALTER TABLE [dbo].[AVAILOPTIONS] ADD CONSTRAINT [AvailOptions_PK] PRIMARY KEY CLUSTERED ([Option Code])GO

ALTER TABLE [dbo].[INSTOPTIONS] ADD CONSTRAINT [InstOptions_PK] PRIMARY KEY CLUSTERED ([Inventory Code], [Option Code])

Page 10: oscaraaronmontecino.comoscaraaronmontecino.com/Documents/IS_DataWharehousing_Mining.docx  · Web viewMIS 430, Fall 2014: Mid-Term Exam. Name: Oscar Aaron . Montecino (Chavez) Total

GO

ALTER TABLE [dbo].[CUSTVEH] ADD CONSTRAINT [CustVeh_PK] PRIMARY KEY CLUSTERED ([Customer Number], [Vin Number])GO

ALTER TABLE [dbo].[SERVREC] ADD CONSTRAINT [ServRec_PK] PRIMARY KEY CLUSTERED ([Service Record Number])GO

ALTER TABLE [dbo].[ROUTSERV] ADD CONSTRAINT [RoutServ_PK] PRIMARY KEY CLUSTERED ([Service Record Number], [Service Type Code])GO

Alter the tables (as needed) to create the necessary foreign keys [7]

--CREATING FOREIGN KEYS--ALTER TABLE [dbo].[INVENTORY] ADD CONSTRAINT [InventoryDealer_FK] FOREIGN KEY ([Dealer Number]) REFERENCES [dbo].[DEALER] ([Dealer Number])ON UPDATE CASCADEGO

ALTER TABLE [dbo].[INVENTORY] ADD CONSTRAINT [InventoryVehicle_FK] FOREIGN KEY ([Vehicle Code]) REFERENCES [dbo].[VEHICLE] ([Vehicle Code])ON UPDATE CASCADEGO

ALTER TABLE [dbo].[NEWVEH] ADD CONSTRAINT [NewvehInventory_FK] FOREIGN KEY ([Inventory Code]) REFERENCES [dbo].[INVENTORY] ([Inventory Code])ON UPDATE CASCADEGO

ALTER TABLE [dbo].[USEDVEH] ADD CONSTRAINT [UsedvehInventory_FK] FOREIGN KEY ([Inventory Code]) REFERENCES [dbo].[INVENTORY] ([Inventory Code])ON UPDATE CASCADEGO

ALTER TABLE [dbo].[TESTDRIVE] ADD CONSTRAINT [TestdriveCustomer_FK] FOREIGN KEY ([Customer Number]) REFERENCES [dbo].[CUSTOMER] ([Customer Number])ON UPDATE CASCADEGO

ALTER TABLE [dbo].[TESTDRIVE] ADD CONSTRAINT [TestdriveInventory_FK] FOREIGN KEY ([Inventory Code]) REFERENCES [dbo].[INVENTORY] ([Inventory Code])ON UPDATE CASCADEGO

ALTER TABLE [dbo].[SALES] ADD CONSTRAINT [SalesInventory_FK] FOREIGN KEY ([Inventory Code]) REFERENCES [dbo].[INVENTORY] ([Inventory Code])ON UPDATE CASCADEGO

Page 11: oscaraaronmontecino.comoscaraaronmontecino.com/Documents/IS_DataWharehousing_Mining.docx  · Web viewMIS 430, Fall 2014: Mid-Term Exam. Name: Oscar Aaron . Montecino (Chavez) Total

ALTER TABLE [dbo].[SALES] ADD CONSTRAINT [SalesCustomer_FK] FOREIGN KEY ([Customer Number]) REFERENCES [dbo].[CUSTOMER] ([Customer Number])ON UPDATE CASCADEGO

ALTER TABLE [dbo].[AVAILOPTIONS] ADD CONSTRAINT [AvailoptionsVehicle_FK] FOREIGN KEY ([Vehicle Code]) REFERENCES [dbo].[VEHICLE] ([Vehicle Code])ON UPDATE CASCADEGO

ALTER TABLE [dbo].[INSTOPTIONS] ADD CONSTRAINT [InstoptionsInventory_FK] FOREIGN KEY ([Inventory Code]) REFERENCES [dbo].[INVENTORY] ([Inventory Code])ON UPDATE CASCADEGO

ALTER TABLE [dbo].[INSTOPTIONS] ADD CONSTRAINT [InstoptionsAvailoptions_FK] FOREIGN KEY ([Option Code]) REFERENCES [dbo].[AVAILOPTIONS] ([Option Code])ON UPDATE CASCADEGO

ALTER TABLE [dbo].[CUSTVEH] ADD CONSTRAINT [CustvehCustomer_FK] FOREIGN KEY ([Customer Number]) REFERENCES [dbo].[CUSTOMER] ([Customer Number])ON UPDATE CASCADEGO

ALTER TABLE [dbo].[CUSTVEH] ADD CONSTRAINT [CustvehVehicle_FK] FOREIGN KEY ([Vehicle Code]) REFERENCES [dbo].[VEHICLE] ([Vehicle Code])ON UPDATE CASCADEGO

ALTER TABLE [dbo].[SERVREC] ADD CONSTRAINT [ServrecCustomer_FK] FOREIGN KEY ([Customer Number]) REFERENCES [dbo].[CUSTOMER] ([Customer Number])ON UPDATE CASCADEGO

ALTER TABLE [dbo].[SERVREC] ADD CONSTRAINT [ServrecCustveh_FK] FOREIGN KEY ([Vin Number]) REFERENCES [dbo].[CUSTVEH] ([Vin Number])ON UPDATE CASCADEGO

ALTER TABLE [dbo].[SERVREC] ADD CONSTRAINT [ServrecDealer_FK] FOREIGN KEY ([Dealer Number]) REFERENCES [dbo].[DEALER] ([Dealer Number])ON UPDATE CASCADEGO

ALTER TABLE [dbo].[ROUTSERV] ADD CONSTRAINT [RoutservServrec_FK] FOREIGN KEY ([Service Record Number]) REFERENCES [dbo].[SERVREC] ([Service Record Number])ON UPDATE CASCADEGO

Page 12: oscaraaronmontecino.comoscaraaronmontecino.com/Documents/IS_DataWharehousing_Mining.docx  · Web viewMIS 430, Fall 2014: Mid-Term Exam. Name: Oscar Aaron . Montecino (Chavez) Total

ALTER TABLE [dbo].[REPSERV] ADD CONSTRAINT [RepservServrec_FK] FOREIGN KEY ([Service Record Number]) REFERENCES [dbo].[SERVREC] ([Service Record Number])ON UPDATE CASCADEGO

Page 13: oscaraaronmontecino.comoscaraaronmontecino.com/Documents/IS_DataWharehousing_Mining.docx  · Web viewMIS 430, Fall 2014: Mid-Term Exam. Name: Oscar Aaron . Montecino (Chavez) Total

The SQL requirements below are for the same database constructed above. Copy-paste from below into your own submission, before filling in the answers.

c) CHECK Constraints: Add the following check constraints to the tables (name check constraints as you see fit). Copy-paste the relevant SQL script below each bullet. [15]

CUSTa. Both driver’s license and date of birth are null, or both are not null. Only one of the two having a null

value is not allowed.

ALTER TABLE [dbo].[CUSTOMER]ADD CONSTRAINT CustomerZipcode_CK CHECK ([Zip Code] IN (NULL) AND [Driver License] IN (NULL))

b. Customer should be at least 18 years old at the time of insert.

ALTER TABLE [dbo].[CUSTOMER]ADD CONSTRAINT CustomerDateofbirth_CK CHECK ([Date of Birth] >= 18)

c. Customer’s zip code should be exactly 5 digits

ALTER TABLE [dbo].[CUSTOMER]ADD CONSTRAINT CustomerZipcode_CK CHECK ([Zip Code] = (“[0-9]”, “[0-9]”, “[0-9]”, “[0-9]”, “[0-9]”) );

DEALERa. At the time of insert, the open date cannot be more than 1 year in future.

ALTER TABLE [dbo].[DEALER]ADD CONSTRAINT DealerOpendate_CK CHECK ([Open Date] <= 1 );

b. Dealer’s zip code should be exactly 5 digits

ALTER TABLE [dbo].[DEALER]ADD CONSTRAINT DealerZipcode_CK CHECK ([Zip Code] IN (“[0-9]”, “[0-9]”, “[0-9]”, “[0-9]”, “[0-9]”) );

c. Dealer’s name must end with letters LLC

ALTER TABLE [dbo].[DEALER]ADD CONSTRAINT DealerName_CK CHECK ([Dealer Name] LIKE “%LLC”);

VEHICLEa. Year cannot be more than one year in future

ALTER TABLE [dbo].[VEHICLE]ADD CONSTRAINT VehicleYear_CK CHECK ([Year] >= “1 year”)Go

b. Date model introduced cannot be more than 3 months in future

ALTER TABLE [dbo].[VEHICLE]ADD CONSTRAINT VehicleDatemodel_CK CHECK ([Date Model Introduced] >= “3 month”)GO

INVENTORY a. New or used can only have values n, N, u, U

ALTER TABLE [dbo].[INVENTORY]ADD CONSTRAINT InventoryNeworused_CK CHECK ([New or Used] IN (‘n’, ‘N’, ‘u’, ‘U’));

Page 14: oscaraaronmontecino.comoscaraaronmontecino.com/Documents/IS_DataWharehousing_Mining.docx  · Web viewMIS 430, Fall 2014: Mid-Term Exam. Name: Oscar Aaron . Montecino (Chavez) Total

b. Date arrived at dealership cannot be more than 1 month in future

ALTER TABLE [dbo].[INVENTORY]ADD CONSTRAINT InventoryDatearrivedatdealership_CK CHECK ([Date Arrived at Dealership] <= “1 month”);

c. Date available in stock cannot be earlier than date arrived at dealership

ALTER TABLE [dbo].[INVENTORY]ADD CONSTRAINT InventoryDateavailableinstock_CK CHECK ([Date Available in Stock] NOT LIKE [Date Arrived at Dealership]);

d. Date sold cannot be earlier than data available in stock

ALTER TABLE [dbo].[INVENTORY]ADD CONSTRAINT InventoryDatesold_CK CHECK ([Date Sold] NOT LIKE [Data Available in Stock]);

e. If data sold is null, the available in stock should be 1. If date sold is not null, the available in stock value should be 0

ALTER TABLE [dbo].[INVENTORY]ADD CONSTRAINT InventoryDatasold_CK CHECK (SUM([Date Sold]) = 1);

NEWVEHa. MSRP is greater than 0

ALTER TABLE [dbo].[NEWVEH]ADD CONSTRAINT NewvehMSRP_CK CHECK ([MSRP] >0);

b. Invoice price is less than MSRP

ALTER TABLE [dbo].[NEWVEH]ADD CONSTRAINT NewvehInvoiceprice_CK CHECK ([Invoice Price] < [MSRP]);

c. Date shipped cannot be more than 1 month in the future

ALTER TABLE [dbo].[NEWVEH]ADD CONSTRAINT NewvehDateshipped_CK CHECK ([Date Shipped] <= “1 month”);

USEDVEHa. Purchase date cannot be in future

ALTER TABLE [dbo].[USEDVEH]ADD CONSTRAINT UsedvehPurchasedate_CK CHECK ([Purchase Date] = NOT NULL);

b. If trade in flag is 1, purchase price cannot be more than 120% of blue book price; or if trade in flag is 0, purchase price cannot be more than 90% of blue book price.

ALTER TABLE [dbo].[USEDVEH]ADD CONSTRAINT UsedvehTradeinflag_CK CHECK ([Trade in Flag] 1 = “120” OR [Trade in Flag] 0 = “90”);

c. Mileage is greater than 0

ALTER TABLE [dbo].[USEDVEH]ADD CONSTRAINT UsedvehMileage_CK CHECK ([Mileage] >0);

d. Blue book value is greater than 0

ALTER TABLE [dbo].[USEDVEH]

Page 15: oscaraaronmontecino.comoscaraaronmontecino.com/Documents/IS_DataWharehousing_Mining.docx  · Web viewMIS 430, Fall 2014: Mid-Term Exam. Name: Oscar Aaron . Montecino (Chavez) Total

ADD CONSTRAINT UsedvehBluebookvalue_CK CHECK ([Blue Book Value] > 0);

TESTDRIVEa. Date of test drive cannot be in future

ALTER TABLE [dbo].[TESTDRIVE]ADD CONSTRAINT TestdriveDateoftestdrive_CK CHECK ([Date of Test Drive] LIKE);

b. Duration of test drive is greater than 0

ALTER TABLE [dbo].[TESTDRIVE]ADD CONSTRAINT TestdriveDurationoftestdrive_CK CHECK ([Duration of Test Drive] LIKE);

SALESa. Sales price is greater than 0

ALTER TABLE [dbo].[SALES]ADD CONSTRAINT SalesSalesprice_CK CHECK ([Sales Price] > 0);

b. Tax amount is not be negative, and not be more than 10% of sales price

ALTER TABLE [dbo].[SALES]ADD CONSTRAINT SalesTaxamount_CK CHECK ([Tax Amount] >= 0 AND [Tax Amount] <= 10);

c. Payment method value is one of C, L, F, O

ALTER TABLE [dbo].[SALES]ADD CONSTRAINT SalesPaymentmethod_CK CHECK ([Payment Method] IN (“C”, “L”, “F”, “O”));

AVAILOPTIONSa. Option cost is not negative

ALTER TABLE [dbo].[AVAILOPTIONS]ADD CONSTRAINT AvailoptionsOptioncost_CK CHECK ([Option Cost] >=0);

b. Option msrp is not negative, and is greater than option cost

ALTER TABLE [dbo].[AVAILOPTIONS]ADD CONSTRAINT AvailoptionsOptionmsrp_CK CHECK ([Option MSRP] >=0 AND [OPTION MSRP] > [Option Cost]);

SERVRECa. Type of service is either RO or REP

ALTER TABLE [dbo].[SERVREC]ADD CONSTRAINT ServrecTypeofservice_CK CHECK ([Type of Service] = “RO” OR [Type of Service] = “REP”);

b. Date brought in is not in future

ALTER TABLE [dbo].[SERVREC]ADD CONSTRAINT ServrecDatebroughtin_CK CHECK ([Date Brought In]);

c. Date service completed is not be later than today, and cannot be earlier than date brought in.

ALTER TABLE [dbo].[SERVREC]ADD CONSTRAINT ServrecDateservicecompleted_CK CHECK ([Date Service Completed] = NOT NULL);

d. Date billed is on or after date service completed.

Page 16: oscaraaronmontecino.comoscaraaronmontecino.com/Documents/IS_DataWharehousing_Mining.docx  · Web viewMIS 430, Fall 2014: Mid-Term Exam. Name: Oscar Aaron . Montecino (Chavez) Total

ALTER TABLE [dbo].[SERVREC]ADD CONSTRAINT ServrecDatebilled_CK CHECK ([Date Billed] = NOT NULL);

e. Total service cost cannot be negative.

ALTER TABLE [dbo].[SERVREC]ADD CONSTRAINT ServrecTotalservicecost_CK CHECK ([Total Service Cost] >= 0);

d) Create the following VIEWS. Copy-paste the relevant SQL script below each bullet. View name: INSTOCK [4]

(Inventory code, Year, Make, Model, Trim Line, VIN number, exterior color, interior color, listed price, dealer name) for only those vehicles in inventory that are available for sale.

CREATE VIEW [INSTOCK] ASSELECT [dbo].[INVENTORY].[Inventory Code], [dbo].[VEHICLE].[Year], [dbo].[VEHICLE].[Make], [VEHICLE].[Model], [dbo].[VEHICLE].[Trim Line], [dbo].[INVENTORY].[VIN number], [dbo].[INVENTORY].[Exterior Color], [dbo].[INVENTORY].[Interior Color], [dbo].[INVENTORY].[Listed Price], [dbo].[DEALER].[Dealer Name]FROM [dbo].[VEHICLE] LEFT JOIN [dbo].[INVENTORY]LEFT JOIN [dbo].[DEALER]GO

Query view above to retrieve listing (all attributes) of cars whose make is Honda or Ford. [2]

SELECT * FROM [INSTOCK]WHERE [Model]= “Honda” AND [model]= “FORD”;

View name: INSTOCKUSED [5](Inventory code, Year, Make, Model, Trim Line, VIN number, exterior color, interior color, mileage, listed price, blue book value, dealer name) for only used vehicles in inventory that are available for sale.

Note: used vehicles are denoted by U or u values for new or used.

CREATE VIEW [INSTOCKUSED] ASSELECT [dbo].[INVENTORY].[Inventory Code], [dbo].[VEHICLE].[Year], [dbo].[VEHICLE].[Make], [VEHICLE].[Model], [dbo].[VEHICLE].[Trim Line], [dbo].[INVENTORY].[VIN number], [dbo].[INVENTORY].[Exterior Color], [dbo].[INVENTORY].[Interior Color], [dbo].[USEDVEH].[Used Mileage], [dbo].[USEDVEH].[Blue Book Value], [dbo].[DEALER].[Dealer Name]FROM [dbo].[VEHICLE] LEFT JOIN [dbo].[INVENTORY]LEFT JOIN [dbo].[DEALER]LEFT JOIN [dbo].[USEDVEH]

ON [dbo].[INVENTORY].[Inventory Code] = [dbo].[USEDVEH].[Inventory Code]GO

Query view above to retrieve listing (all attributes) of cars whose make is Honda or Ford. The list should only consist of cars with mileage under 50000, or listed price is no more than 90% of blue book value. [3]

SELECT * FROM [INSTOCKUSED]WHERE ([Model]= “Honda” OR [model]= “FORD”) AND [Mileage] <= 0 AND [Listed Price] < 90 ;

e) Create the following triggers. Copy-paste the relevant SQL script below each bullet. [12] Trigger: TRG_CARSALES

When a vehicle is sold, trigger should update the related record in INVENTORY table as follows:1. Date sold is today’s date2. Available for sale is set to 0

IF UPDATE(TRG_CARSALES)

Page 17: oscaraaronmontecino.comoscaraaronmontecino.com/Documents/IS_DataWharehousing_Mining.docx  · Web viewMIS 430, Fall 2014: Mid-Term Exam. Name: Oscar Aaron . Montecino (Chavez) Total

INSERT INTO INVENTORY([Vehicle Code], [Year], [Make], [Model], [Trim Line], [Date Model Introduced], [MSRP]) SELECT INVENTORY.[Vehicle Code], INVENTORY.[Year], INVENTORY.[Make], INVENTORY.[Model], INVENTORY.[Trim Line], INVENTORY.[Date Model Introduced], INVENTORY.[MSRP] FROM INSERTED ; DELETE FROM INVENTORY WHERE [INVENTORY].[Date Sold] IN (test drive code, customer number, date of test drive, duration of test drive, inventory code SELECT inserted.[Date Sold] FROM INSERTED WHERE [Available for Sale] = 0 ) ;

Trigger: TRG_TESTDRIVEa. When a new test drive is recorded, trigger should check the related record in INVENTORY to make sure

that the vehicle is available for sale (i.e. the value for available for sale is 1). If the vehicle is not available for sale, the insert should be disallowed (i.e. rollback).

IF UPDATE([TRG_TESTDRIVE])INSERT INTO TESTDRIVE(test drive code, customer number, date of test drive, duration of test drive, inventory code) FROM INSERTED test drive code, customer number, date of test drive, duration of test drive, inventory code ; DELETE FROM TESTDRIVE WHERE [TESTDRIVE].[New Test Drive] IN ( SELECT inserted.[New Test Drive] FROM INSERTED WHERE [Available for Sale] = 1 ) ;

f) The company decides to allow customers to search the website to find the available inventory from different dealerships. This has feature is extremely popular, and the number of customers browsing the inventory on the web easily runs into few hundred website visits every day. Following that the database administrator (DBA) observes the following:

Almost all searches for the available inventory are for either new vehicles or used vehicles, and rarely both. The DBA also realizes that both type of vehicles have some information in common (Inventory code, Year, Make,

Model, Trim Line, VIN number, exterior color, interior color, listed price, dealer name) and additional information that is different. The different information is as follows: 1) for used vehicle comes from all attributes of USEDVEH table, and 2) for new vehicles comes from all attributes of NEWVEH table.

The inventory table is not very large in terms of number of records. New additions to inventory mostly occur at the beginning of the month at one time. Very few records (5 to 20) are added or changed every day.

For business purpose, changes made to the inventory are only reflected on website once every 24 hours.

Carefully consider the scenario, and - Identify and describe three best options you may have to speeding up the query performance on the website. For each

option, justify why it is one of the options and how it would help speed up the query performance [6]1) Indexing: since all main searches are made first with new vehicles or used, data should be index within this to help speed query. 2) Partition: Can help organize data into smaller tables to help speed querying. This would help get the info the customer wants from the website. 3) View: Create views so that it helps “hide” unnecessary information and speed up search. This will help to decrease confusion on the website.

- Which of the three options would you recommend as the best option, and explain why? [4]

Page 18: oscaraaronmontecino.comoscaraaronmontecino.com/Documents/IS_DataWharehousing_Mining.docx  · Web viewMIS 430, Fall 2014: Mid-Term Exam. Name: Oscar Aaron . Montecino (Chavez) Total

Personally, I would go VIEWS because not only can you partition with in, you help eliminate unnecessary information that the customer doesn’t care about and help bring data from other tables into one “virtual” table. Help increase user interface and user experience.

Note: for all written answers below – you MUST write in your own words. Do not copy ad-verbatim from any source (book, class notes, web, etc.). Type your answers below each question.

2. In context of a relational databasea) Briefly explain what is a VIEW? [2]

View is a virtual table that allows the person to see specific data from multiple entities (real tables). The view is not a query or not part of the database schema. View is not an entity (real table) that stores data. View restricts certain information by hiding confidential data. It is primarily a UI (user interface) & UX (user experience) resource that optimizes access by relevance in one single window. Whereas entities (real tables) has rows of data, named columns, and ability to insert, update, delete operations on underlying data.

b) Use the above database to identify one example each, along with brief explanation, to explain three different objectives for creating VIEWS. [3]

1) Receipt of car sale: The reason for using VIEW in here would help give the customer quick information on price, tax, model, year, make, VIN number. This would ‘hide’ information that the customer doesn’t need or would be confused on. 2) Web Search: giving a quick access to individuals without personal company information. A company wouldn’t want data to be posted in public about their performance, past customer information, etc. 3) Inventory Record: By having a VIEW for inventory record, we can exclude information on past cost, date sold, color of the car (inside and out), and much more. Inventory record would solely have information what we have on hand, the model, type, year, to help make proper orders.

c) Evaluate the following statement, and justify your position. You may use an example if you need to illustrate your point. [2]In a denormalized database (a database that is not normalized) there would be no need for creating views since assimilation of data from multiple different tables is not required.

TRUE / FALSE

Justification:

3. Horizontal Partitioninga) Briefly describe what is Horizontal Partitioning of a table. [2]

It is data of partitioned table to divide into smaller tables. Single entity still occurs within the table. It allows the portion of the table being handled in querying to be smaller. This would result in a speed up response and accessibility to the query. The minor problem with this is query starts to slow down when more than one partition is needed to get records.

b) Based on the database built above, construct one example each, along with brief explanation, to illustrate the different situations, and types of Horizontal Partitions. [4]

One example we can do a horizontal partition is by partitioning the vehicle by year. IF we were to separate them by the year made, the response for query would be faster. That way, the consumer can get information that they need.

4. Identify and explain the main differences between primary/clustered and secondary/non-clustered indexes. [3]

Page 19: oscaraaronmontecino.comoscaraaronmontecino.com/Documents/IS_DataWharehousing_Mining.docx  · Web viewMIS 430, Fall 2014: Mid-Term Exam. Name: Oscar Aaron . Montecino (Chavez) Total

In a primary/clustered, only maximum of one can occur in a table. In this case, Primary Keys will default as needed. Whereas Secondary/non-clustered indexes have tables that are not sorted in order, but index is. You see, more than 1 non-cluster can occur in a table.

5. In a particular table, it is decided to build a secondary index on the column named carMake. The values contained in the column are shown below. Create the entries for the secondary index, and clearly show which index entry tracks which record. [2]

cIndex carMakeAlfa Romero PaganiAston Martin Aston Martin*Aston Martin Alfa Romeo*Bugatti Bugatti *Cadillac Cadillac*Cadillac Lincoln*Cadillac Cadillac*Lincoln Aston Martin*Lincoln Lincoln*Lincoln Lincoln*Pagani Cadillac*

6. For the carMake column shown above, it decided to build a primary index instead of the secondary index. Using the same values as shown above, create the entries for the primary index, and rewrite the values in column to show any corresponding changes. Clearly show which index entry tracks which record. [2]

ZipIndex carMakeAlfa Romero PaganiAston Martin Aston MartinBugatti Alfa RomeoCadillac BugattiLincoln CadillacPagani Lincoln

CadillacAston MartinLincolnLincolnCadillac