Question

In: Computer Science

CREATE TABLE DRIVER( ENUM         DECIMAL(12) NOT NULL, LNUM         DECIMAL(8)    NOT NULL,...

CREATE TABLE DRIVER(
ENUM         DECIMAL(12) NOT NULL,
LNUM         DECIMAL(8)    NOT NULL,
STATUS         VARCHAR(10) NOT NULL,
CONSTRAINT DRIVER_PKEY PRIMARY KEY(ENUM),
CONSTRAINT DRIVER_UNIQUE UNIQUE(LNUM),
CONSTRAINT DRIVER_FKEY FOREIGN KEY(ENUM) REFERENCES EMPLOYEE(ENUM),
CONSTRAINT DRIVER_STATUS CHECK ( STATUS IN ('AVAILABLE', 'BUSY', 'ON LEAVE')) );

(1)   Modify a consistency constraint of the sample database such that after a modification
        it is possible to record in the database information about the drivers who are sick.   */

CREATE TABLE TRUCK(
REGNUM         VARCHAR(10) NOT NULL,
CAPACITY    DECIMAL(7)    NOT NULL,
WEIGHT         DECIMAL(7)    NOT NULL,
STATUS         VARCHAR(10) NOT NULL,
CONSTRAINT TRUCK_PKEY PRIMARY KEY(REGNUM),
CONSTRAINT TRUCK_STATUS CHECK ( STATUS IN ('AVAILABLE', 'USED', 'MAINTAINED')),
CONSTRAINT TRUCK_WEIGHT CHECK ( WEIGHT > 0.0 AND WEIGHT < 500000 ),
CONSTRAINT TRUCK_CAPACITY CHECK ( CAPACITY > 0.0 AND CAPACITY < 100000 ) );

2. Modify a structure and consistency constraint of the sample database such that after
        a modification it is possible to add information about the total number of repairs
        performed on each truck. Assume that, a truck cannot be repaired more than 1000 times.

CREATE TABLE TRIP(
TNUM         DECIMAL(10) NOT NULL,
LNUM         DECIMAL(8)    NOT NULL,
REGNUM         VARCHAR(10) NOT NULL,
TDATE       DATE    NOT NULL,
CONSTRAINT TRIP_PKEY PRIMARY KEY (TNUM),
CONSTRAINT TRIP_CKEY UNIQUE (LNUM, REGNUM, TDATE),
CONSTRAINT TRIP_FKEY1 FOREIGN KEY (LNUM) REFERENCES DRIVER(LNUM),
CONSTRAINT TRIP_FKEY2 FOREIGN KEY (REGNUM) REFERENCES TRUCK(REGNUM) );

3. Modify a structure and consistency constraint of the sample database such that after
        a modification it is possible to store in the database optional information about
        the cost of each trip. Assume, that cost of a single trip is a positive number not
        greater that 9999.99.

Solutions

Expert Solution

# I have solved all three problems.Adding comments for detailed explanation

CREATE TABLE DRIVER(
ENUM         DECIMAL(12) NOT NULL,
LNUM         DECIMAL(8)    NOT NULL,

HEALTH VARCHAR(10) NOT NULL,          #-----ADDING HEALTH VARIABLE
STATUS         VARCHAR(10) NOT NULL,
CONSTRAINT DRIVER_PKEY PRIMARY KEY(ENUM),
CONSTRAINT DRIVER_UNIQUE UNIQUE(LNUM),
CONSTRAINT DRIVER_FKEY FOREIGN KEY(ENUM) REFERENCES EMPLOYEE(ENUM),
CONSTRAINT DRIVER_STATUS CHECK ( STATUS IN ('AVAILABLE', 'BUSY', 'ON LEAVE'))

,CONSTRAINT DRIVER_HEALTH CHECK ( HEALTH IN ('HEALTHY','SICK')) #---CHECKING ITS CONSTRAINT

);

---------------------------2ND PART-------------------------

CREATE TABLE TRUCK(
REGNUM         VARCHAR(10) NOT NULL,

REPAIR_NUMBER DECIMAL(5) NOT NULL,       #ADDING REPAIR NUMBER AS A VARIABLE
CAPACITY    DECIMAL(7)    NOT NULL,
WEIGHT         DECIMAL(7)    NOT NULL,
STATUS         VARCHAR(10) NOT NULL,
CONSTRAINT TRUCK_PKEY PRIMARY KEY(REGNUM),
CONSTRAINT TRUCK_STATUS CHECK ( STATUS IN ('AVAILABLE', 'USED', 'MAINTAINED')),
CONSTRAINT TRUCK_WEIGHT CHECK ( WEIGHT > 0.0 AND WEIGHT < 500000 ),

CONSTRAINT TRUCK_REPAIR CHECK ( REPAIR_NUMBER <= 1000 ),       #CHECKING its values


CONSTRAINT TRUCK_CAPACITY CHECK ( CAPACITY > 0.0 AND CAPACITY < 100000 ) );

--------------------------------------------3RD PART------------------------------------

CREATE TABLE TRIP(
TNUM         DECIMAL(10) NOT NULL,
LNUM         DECIMAL(8)    NOT NULL,
REGNUM         VARCHAR(10) NOT NULL,
TDATE       DATE    NOT NULL,

COST_OF_TRIP DECIMAL(5,2) NOT NULL,            # adding variable to store variable.
CONSTRAINT TRIP_PKEY PRIMARY KEY (TNUM),

CONSTRAINT TRIP_COST CHECK(COST_OF_TRIP > 0.0 AND COST_OF_TRIP < 9999.99), #checking its constraint
CONSTRAINT TRIP_CKEY UNIQUE (LNUM, REGNUM, TDATE),
CONSTRAINT TRIP_FKEY1 FOREIGN KEY (LNUM) REFERENCES DRIVER(LNUM),
CONSTRAINT TRIP_FKEY2 FOREIGN KEY (REGNUM) REFERENCES TRUCK(REGNUM) );


Related Solutions

Based on this code: CREATE TABLE DEPARTMENT ( DepartmentName Char(35) NOT NULL, BudgetCode Char(30) NOT NULL,...
Based on this code: CREATE TABLE DEPARTMENT ( DepartmentName Char(35) NOT NULL, BudgetCode Char(30) NOT NULL, OfficeNumber Char(15) Not Null, DepartmentPhone Char(12) NOT NULL, CONSTRAINT DEPARTMENT_PK primary key(DepartmentName) ); CREATE TABLE EMPLOYEE( EmployeeNumber Int NOT NULL AUTO_INCREMENT, FirstName Char(25) NOT NULL, LastName Char(25) NOT NULL, Department Char(35) NOT NULL DEFAULT 'Human Resources', Position Char(35) NULL, Supervisor Int NULL, OfficePhone Char(12) NULL, EmailAddress VarChar(100) NOT NULL UNIQUE, CONSTRAINT EMPLOYEE_PK PRIMARY KEY(EmployeeNumber), CONSTRAINT EMP_DEPART_FK FOREIGN KEY(Department) REFERENCES DEPARTMENT(DepartmentName) ON UPDATE CASCADE, CONSTRAINT...
Create a table book_store with columns Book_id VARCHAR(255) NOT NULL, Book_Name VARCHAR(255) NOT NULL, Book_genre VARCHAR(255)...
Create a table book_store with columns Book_id VARCHAR(255) NOT NULL, Book_Name VARCHAR(255) NOT NULL, Book_genre VARCHAR(255) NOT NULL, Status VARCHAR(255) NOT NULL, PRIMARY KEY (Book_id) Create a table book with columns Book_id VARCHAR(255) NOT NULL, Book_Name VARCHAR(255) NOT NULL, Book_release integer, Book_price integer , Publisher Varchar(10), Book_genre VARCHAR(255) NOT NULL, PRIMARY KEY (Book_id) CREATE TABLE price_logs with columns id INT(11) NOT NULL AUTO_INCREMENT, Book_id VARCHAR(255) NOT NULL, Old_Book_price DOUBLE NOT NULL, New_Book_price DOUBLE NOT NULL, updated_at TIMESTAMP NOT NULL DEFAULT...
Create a table book_store with columns Book_id VARCHAR(255) NOT NULL, Book_Name VARCHAR(255) NOT NULL, Book_genre VARCHAR(255)...
Create a table book_store with columns Book_id VARCHAR(255) NOT NULL, Book_Name VARCHAR(255) NOT NULL, Book_genre VARCHAR(255) NOT NULL, Status VARCHAR(255) NOT NULL, PRIMARY KEY (Book_id) Create a table book with columns Book_id VARCHAR(255) NOT NULL, Book_Name VARCHAR(255) NOT NULL, Book_release integer, Book_price integer , Publisher Varchar(10), Book_genre VARCHAR(255) NOT NULL, PRIMARY KEY (Book_id) CREATE TABLE price_logs with columns id INT(11) NOT NULL AUTO_INCREMENT, Book_id VARCHAR(255) NOT NULL, Old_Book_price DOUBLE NOT NULL, New_Book_price DOUBLE NOT NULL, updated_at TIMESTAMP NOT NULL DEFAULT...
CREATE TABLE youtubevideos( url VARCHAR(150), title VARCHAR(50), description VARCHAR(200), comid INTEGER NOT NULL, postuserVARCHAR(50) NOT NULL,...
CREATE TABLE youtubevideos( url VARCHAR(150), title VARCHAR(50), description VARCHAR(200), comid INTEGER NOT NULL, postuserVARCHAR(50) NOT NULL, postdate DATE, PRIMARY KEY (email), FOREIGN KEY (comid) REFERENCES Comedians(comid), FOREIGN KEY (postuser) REFERENCES Users(email)); CREATE TABLE Users( email VARCHAR(50), password VARCHAR(50), firstname VARCHAR(50), lastname VARCHAR(50), gender CHAR(1), age INTEGER, PRIMARY KEY (email)); CREATE TABLE Comedians( comid INTEGER, firstname VARCHAR(50), lastname VARCHAR(50), birthday DATE, VARCHAR(50), PRIMARY KEY(comid)); CREATE TABLE Reviews( reviewid INTEGER NOT NULL AUTO_INCREMENT, remark VARCHAR(100), rating CHAR(1), //P.F.G.E author VARCHAR(50) NOT NULL,...
review the financial statements of the march of dimes for 2013 as presented in table 12-8....
review the financial statements of the march of dimes for 2013 as presented in table 12-8. comment as you can (even in the absence of guidelines as to what constitutes norms for comparable foundations) on the fiscal strength of the organization as of Dec. 21, 2013 with respect to: liquidity, burden of debt relative to assets, adequacy of available resources to meet expenditures, current fiscal performance as indicated by surpluses or deficits and riskiness of revenue stream
8.   Create a truth table and determine the results for the following equation and values Equation :...
8.   Create a truth table and determine the results for the following equation and values Equation : bool b = ((a+4< 7) || ((b-a > 10) && !(c*a == 8))) Values :   a = 2; b = 8; c = 4 9. Write a program using Atom and submit via Blackboard. a. Request an integer whole dollar amount from the console. b. Using the least amount of bills ($50,$20,$10,$5,$1) necessary, calculate how many of each bill type you will need to get...
How to create a driver base forecasting withcost centers?
How to create a driver base forecasting withcost centers?
The table below shows the quantity measured for 12 samples (in kg). Create an xbar-chart and...
The table below shows the quantity measured for 12 samples (in kg). Create an xbar-chart and an R-chart and plot the values for the 12 samples. Comment on whether or not the process is in control or not. Also create an upper and lower spec limit for the data that results in a Cpk of at least 2.33. Sample Day 1 64.43 63.40 65.58 65.03 65.42 68.99 68.63 67.34 67.00 64.07 65.64 63.73 Day 2 65.53 67.43 66.63 64.54 64.76...
The table below shows pairs of body temperature at 8 AM and 12 AM. Use a...
The table below shows pairs of body temperature at 8 AM and 12 AM. Use a 0.05 significance  test the claim that the mean difference between body temperature measured at 8 AM and 12 AM is zero 8 AM 96.6 97.0 97.0 97.8 97.0 97.4 96.6 Noon 99.0 98.4 98.0 98.6 98.5 98.9 98.4 Critical Values: z0.005 = 2.575, z0.01 = 2.325, z0.025 = 1.96, z0.05 = 1.645 When d.f.=6: t0.005 = 3.707, t0.01 = 3.143, t0.025 = 2.447, t0.05 =...
Create table, create primary and foreign key constraints. Create index on the table to satisfy a...
Create table, create primary and foreign key constraints. Create index on the table to satisfy a query with aggregate functions.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT