(50) NOT NULL,/* First name */ LNAME VARCHAR(50) NOT NULL,/* Last name */ DOB DATE NULL,/* Date of birth */ CONSTRAINT EMPLOYEE_PKEY PRIMARY KEY(ENUM) ); CREATE TABLE DRIVER( ENUM DECIMAL(12) NOT NULL,/* Employee number */ LNUM DECIMAL(8) NOT NULL,/* Driving license number

Oracle 12c: SQL
3rd Edition
ISBN:9781305251038
Author:Joan Casteel
Publisher:Joan Casteel
Chapter2: Basic Sql Select Statements
Section: Chapter Questions
Problem 10RQ: What is a NULL value?
icon
Related questions
icon
Concept explainers
Question

CREATE TABLE EMPLOYEE(
ENUM DECIMAL(12) NOT NULL,/* Employee number */
FNAME VARCHAR(50) NOT NULL,/* First name */
LNAME VARCHAR(50) NOT NULL,/* Last name */
DOB DATE NULL,/* Date of birth */
CONSTRAINT EMPLOYEE_PKEY PRIMARY KEY(ENUM) );
CREATE TABLE DRIVER(
ENUM DECIMAL(12) NOT NULL,/* Employee number */
LNUM DECIMAL(8) NOT NULL,/* Driving license number */
STATUS VARCHAR(10) NOT NULL,/* Driver status */
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')) );
CREATE TABLE TRUCK(
REGNUM VARCHAR(10) NOT NULL,/* Registration number */
CAPACITY DECIMAL(7) NOT NULL,/* Capacity */
WEIGHT DECIMAL(7) NOT NULL,/* Weight */
STATUS VARCHAR(10) NOT NULL,/* Present status */
CONSTRAINT TRUCK_PKEY PRIMARY KEY(REGNUM),
CONSTRAINT TRUCK_STATUS CHECK
( STATUS IN ('AVAILABLE', 'USED', 'MAINTAINED')),
CONSTRAINT TRUCK_WEIGHT CHECK
( WEIGHT > 0.0 AND WEIGHT < 500 ),
CONSTRAINT TRUCK_CAPACITY CHECK
( CAPACITY > 0.0 AND CAPACITY < 100 ) );
CREATE TABLE TRIP(
TNUM DECIMAL(10) NOT NULL,/* Trip number */
LNUM DECIMAL(8) NOT NULL,/* Driving license number */
REGNUM VARCHAR(10) NOT NULL,/* Truck registration number */
TDATE DATE NOT NULL,/* Trip date */
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) );
CREATE TABLE TRIPLEG(
TNUM DECIMAL(10) NOT NULL,/* Trip number */
LEGNUM DECIMAL(2) NOT NULL,/* Leg number */
DEPARTURE VARCHAR(30) NOT NULL,/* Departure city */
DESTINATION VARCHAR(30) NOT NULL,/* Destination city */
CONSTRAINT TRIPLEG_PKEY PRIMARY KEY (TNUM, LEGNUM),
CONSTRAINT TRIPLEG_UNIQUE UNIQUE(TNUM, DEPARTURE, DESTINATION),
CONSTRAINT TRIPLEG_FKEY1 FOREIGN KEY (TNUM) REFERENCES TRIP(TNUM) );

Refer to above table

Assume, that we would like to verify the following logical consistency constraint imposed on the contents of a sample database. "A truck cannot be used for more that 100 trips" Write SQL statements that perform the following actions. (1) First, create a relational table MESSAGE with information about the contents of a sample database that violate the following consistency constraint listed above. A relational table MESSAGE must consist of two columns. The first column contains truck registration numbers and the second column contains the total number of trips for all trucks that have been used for more than 100 trips. (2) Next, list the contents of a relational table MESSAGE in the following way Truck have been used for trips For example, if a truck with registration number PKR856 have been used 120 time then the following line must be listed Truck PKR856 have been used for 120 trips (3) Next, make the contents of a relational table MESSAGE permanent. (4) Finally, drop a relational table MESSAGE.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Query Syntax
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Oracle 12c: SQL
Oracle 12c: SQL
Computer Science
ISBN:
9781305251038
Author:
Joan Casteel
Publisher:
Cengage Learning