Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is my database SQL so far (all i need is the code) CREATE TABLE Customer ( CustomerID INT NOT NULL, CustomerLastName VARCHAR(30) NOT NULL,

This is my database SQL so far (all i need is the code)

CREATE TABLE Customer ( CustomerID INT NOT NULL,

CustomerLastName VARCHAR(30) NOT NULL,

CustomerFirstName VARCHAR(30) NOT NULL,

CustomerStreetName VARCHAR(50),

CustomerStreet VARCHAR(30),

CustomerCity VARCHAR(30),

CustomerState CHAR(2),

CustomerZip CHAR(10),

CustomerCellPhone NUMERIC(12,2) DEFAULT 0,

CustomerHomePhone NUMERIC(12,2) DEFAULT 0,

CONSTRAINT Customer_PK PRIMARY KEY (CustomerID) );

CREATE TABLE Vehicle ( VehicleID INT NOT NULL,

CustomerID INT NOT NULL,

Year INT NOT NULL,

Make VARCHAR(20) NOT NULL,

Model VARCHAR(20) NOT NULL,

LicenseNumber VARCHAR(20),

Color VARCHAR(20),

VIN VARCHAR(17) NOT NULL,

CONSTRAINT Vehicle_PK PRIMARY KEY (VehicleID) );

CREATE TABLE ServiceBooking

( BookingNO INT NOT NULL,

VehicleID INT NOT NULL,

DateTimeRequested DateTime NOT NULL,

ServiceRequest VARCHAR(250) NOT NULL,

NeedsLoaner CHAR(1) ,

Waiting CHAR(1),

CONSTRAINT ServiceBooking_PK PRIMARY KEY (BookingNO),

CONSTRAINT ServiceBooking_FK Foreign KEY (VehicleID)

REFERENCES Vehicle(VehicleID) );

Here are the directions:

1. Basic CREATE TABLE Statement Requirements Use the table descriptions in the Intercollegiate Database background document. To ensure uniqueness, add the prefix, IAD to each table name. For example, EventRequest should be IADEventRequest. For primary key fields (CustNo, LocNo, EventNo, PlanNo, EmpNo, ResNo, and FacNo), use the VARCHAR data type with length 8. For consistency, corresponding foreign keys (such as EventRequest.CustNo) should also be the same data type and length. For the columns involving only dates use the DATE data type. The EventPlanLine.TimeStart and EventPlanLine.TimeEnd columns will store both date and time data so you should use the DATETIME data type. Use CHAR(1) for the Customer.Internal column.

2. Constraints After writing the basic CREATE TABLE statements, modify the statements with constraints and default clauses. You should specify a meaningful name for each CONSTRAINT clause and end with an appropriate suffix. For each primary key, you should specify a PRIMARY KEY constraint clause. For single column primary keys (CustNo, LocNo, EventNo, PlanNo, EmpNo, ResNo, and FacNo), only one field is in parentheses. For multiple column primary keys (combination of PlanNo and LineNo), all relevant keys are in parentheses. For each foreign key, you should specify a FOREIGN KEY constraint clause. The constraint clauses should be separate. Specify the ON DELETE CASCADE clause for the foreign key constraints supporting the relationships from EventPlan to EventPlanLine and EventRequest to EventPlan. (Database Creation) Define NOT NULL constraint clauses for all columns except eventplan.empno, EventRequest.DateAuth, EventRequest.BudNo, and EventPlan.Notes. Make sure that you define NOT NULL constraints for the PK of each table. Set the default value using the DEFAULT keyword as follows: Pending for EventRequest.Status, Y for Customer.Internal, 80217 for Customer.Zip, and todays date (use the GETDATE() function) for EventRequest.DateReq. You need to specify the DEFAULT keyword before the CONSTRAINT keyword for column definitions containing inline constraint clauses. String constants must be specified inside single quotes. You must use straight quotes not smart quotes. Use an editor such as Notepad or Notepad++ to ensure no spurious characters are included. Define a named CHECK constraint to restrict the eventrequest.status column to have a value of Pending, Denied, or Approved. See CHECK constraint examples on textbook page 654. You should use the IN operator in this constraint. Define named CHECK constraints to ensure that the resource.rate and eventrequest.estaudience are greater than 0. Define a named CHECK constraint involving EventRequest.DateAuth and EventRequest.DateReq. Date authorized should be larger (chronologically later) than date requested. The tricky part is that DateAuth can have null values. For example, when an event is initially requested, the authorization date is not known. To receive credit for this constraint, your rule should allow a row with a null (blank) value for DateAuth. When the DateAuth value is not null, it should be larger (chronologically later) than the DateReq value. Define a named CHECK constraint involving EventPlanLine.TimeStart and EventPlanLineTimeEnd. The start time should be smaller (chronologically before) than the end time.

3. Loading Data I will provide a text file containing SQL INSERT statements for loading the data. You need to create the tables before inserting rows in each table. You need to insert rows in parent tables 9/10/2018 Assignment 1 (Database Creation) Page 3 before child tables that reference parent tables. The INSERT statements in the file are in a proper order for loading into the tables.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management With Website Development Applications

Authors: Greg Riccardi

1st Edition

0201743876, 978-0201743876

More Books

Students also viewed these Databases questions

Question

Is more control necessarily better in communication?

Answered: 1 week ago

Question

Understand how customers respond to effective service recovery.

Answered: 1 week ago

Question

Know the principles of effective service recovery systems.

Answered: 1 week ago