Question

Create a DDL MYSQL create a database where a user can sell their vehicle, lease a vehicle, financ...

create a DDL MYSQL

create a database where a user can sell their vehicle, lease a vehicle, finance a cart, or donate their current vehicle.

Also we'll have a adminstrator that will have access to the customers and vehicles.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Customers(CID, first_name, Last_Name, Address)

Vehicle(VID, Mileage, Location, Size, Transmission)

Reservations(CID,VID, Start_Date, End_Date)

Note :

->Vehicle.transmission can have two values ‘manual’ and ‘automatic’.

->Vehicle.size can have following values. ‘compact’, ‘mid-size’, ‘full-size’, ‘premium’ and ‘luxury’. The default size is compact.

Create customers table

CREATE TABLE Customers

(

CID varchar2(5) PRIMARY KEY,

FIRST_NAME varchar2(20),

LAST_NAME varchar2(15),

ADDRESS varchar2(30)

);

Create vehicle table

CREATE TABLE Vehicle

(

VID varchar2(5) PRIMARY KEY,

MILEAGE NUMBER(7,2),

LOCATION varchar2(20),

VSIZE varchar2(30) CHECK (VSIZE IN('COMPACT','MID-SIZE','FULL-SIZE','PREMIUM','LUXURY')),

TRANSMISSION varchar2(10) CHECK (TRANSMISSION IN('MANUAL','AUTOMATIC'))

);

Create reservation table

CREATE TABLE Reservation

(

CID varchar2(5) REFERENCES Customers(CID),

VID varchar2(5) REFERENCES Vehicle(VID),

START_DATE DATE,

END_DATE DATE,

PRIMARY KEY(CID,VID)

);

Description / definition of customer table

DESC CUSTOMERS;

Output :

Name Null? Type

CID NOT NULL VARCHAR2(5)

FIRST_NAME VARCHAR2(20)

LAST_NAME VARCHAR2(15)

ADDRESS VARCHAR2(30)

Description / definition of vehicle table

DESC VEHICLE;

Output :

Name Null? Type

VID NOT NULL VARCHAR2(5)

MILEAGE NUMBER(7,2)

LOCATION VARCHAR2(20)

VSIZE VARCHAR2(30)

TRANSMISSION VARCHAR2(10)

Description / definition of reservation table

DESC RESERVATION;

Output :

Name Null? Type

CID NOT NULL VARCHAR2(5)

VID NOT NULL VARCHAR2(5)

START_DATE DATE

END_DATE DATE

Insert statements

INSERT STATEMENT FOR CUSTOMER TABLE

INSERT INTO Customers

(CID,FIRST_NAME,LAST_NAME,ADDRESS) VALUES ('101','KRUNAL','PATEL','MANINAGAR,AHMD');

INSERT INTO Customers

(CID,FIRST_NAME,LAST_NAME,ADDRESS) VALUES ('102','BHAVESH','MODI','VADAJ,AHMD');

INSERT INTO Customers

(CID,FIRST_NAME,LAST_NAME,ADDRESS) VALUES ('103','DARSHAN','DERASARI','HIMANTNAGAR');

INSERT INTO Customers

(CID,FIRST_NAME,LAST_NAME,ADDRESS) VALUES ('104','VISHAL','DAVE','ISSANPUR,AHMD');

INSERT INTO Customers

(CID,FIRST_NAME,LAST_NAME,ADDRESS) VALUES ('105','SAGAR','SHAH','VATVA,AHMD');

INSERT STATEMENT FOR VEHICLE TABLE

INSERT INTO Vehicle (VID,MILEAGE,LOCATION,VSIZE,TRANSMISSION)

VALUES ('V-101','70','AHMD','COMPACT','AUTOMATIC');

INSERT INTO Vehicle (VID,MILEAGE,LOCATION,VSIZE,TRANSMISSION)

VALUES ('V-102','50','SURAT','COMPACT','AUTOMATIC');

INSERT INTO Vehicle (VID,MILEAGE,LOCATION,VSIZE,TRANSMISSION)

VALUES ('V-103','10','AHMD','MID-SIZE','MANUAL');

INSERT INTO Vehicle (VID,MILEAGE,LOCATION,VSIZE,TRANSMISSION)

VALUES ('V-104','30','AHMD','MID-SIZE','AUTOMATIC');

INSERT INTO Vehicle (VID,MILEAGE,LOCATION,VSIZE,TRANSMISSION)

VALUES ('V-105','15','VADODARA','FULL-SIZE','AUTOMATIC');

INSERT INTO Vehicle (VID,MILEAGE,LOCATION,VSIZE,TRANSMISSION)

VALUES ('V-106','20','AHMD','LUXURY','AUTOMATIC');

INSERT INTO Vehicle (VID,MILEAGE,LOCATION,VSIZE,TRANSMISSION)

VALUES ('V-107','50','AHMD','LUXURY','MANUAL');

INSERT STATEMENT FOR RESERVATION TABLE

INSERT INTO Reservation

(CID,VID,START_DATE,END_DATE) VALUES ('101','V-101','10-JAN-2001','10-FEB-2005');

INSERT INTO Reservation

(CID,VID,START_DATE,END_DATE) VALUES ('102','V-102','12-MAR-2001','10-JUN-2006');

INSERT INTO Reservation

(CID,VID,START_DATE,END_DATE) VALUES ('103','V-103','15-FEB-1999','09-SEP-2005');

INSERT INTO Reservation

(CID,VID,START_DATE,END_DATE) VALUES ('105','V-105','15-FEB-2003','09-SEP-2005');

Display records of customer table

SELECT * FROM CUSTOMERS;

Output :

CID FIRST_NAME LAST_NAME ADDRESS

101 KRUNAL PATEL MANINAGAR,AHMD

102 BHAVESH MODI VADAJ,AHMD

103 DARSHAN DERASARI HIMANTNAGAR

104 VISHAL DAVE ISSANPUR,AHMD

105 SAGAR SHAH VATVA,AHMD

Display records of vehicle table

SELECT * FROM VEHICLE;

Output :

VID MILEAGE LOCATION VSIZE TRANSMISSI

V-101 70 AHMD COMPACT AUTOMATIC

V-102 50 SURAT COMPACT AUTOMATIC

V-103 10 AHMD MID-SIZE MANUAL

V-104 30 AHMD MID-SIZE AUTOMATIC

V-105 15 VADODARA FULL-SIZE AUTOMATIC

V-106 20 AHMD LUXURY AUTOMATIC

V-107 50 AHMD LUXURY MANUAL

Display records of reservation table

SELECT * FROM RESERVATION;

Output :

CID VID START_DAT END_DATE

101 V-101 10-JAN-01 10-FEB-05

102 V-102 12-MAR-01 10-JUN-06

103 V-103 15-FEB-99 09-SEP-05

105 V-105 15-FEB-03 09-SEP-05

Display vehicles which are reserved for maximum times

SELECT * FROM VEHICLE WHERE VID =

   (

   SELECT VID FROM RESERVATION WHERE ROUND((END_DATE-START_DATE)/365) =

   (SELECT MAX(ROUND((END_DATE-START_DATE)/365)) AS "MAXIMUM TIME"FROM RESERVATION)

   );

Output :

VID MILEAGE LOCATION VSIZE TRANSMISSI

V-103 10 AHMD MID-SIZE MANUAL

Display vehicles size is the most preferred.

SELECT VSIZE FROM VEHICLE WHERE MILEAGE = (SELECT MAX(MILEAGE) FROM VEHICLE);

Output :

VSIZE

COMPACT

Find location and total mileage of all vehicles specific to each respective location.

SELECT LOCATION,SUM(MILEAGE) FROM VEHICLE GROUP BY LOCATION;

Output :

OCATION SUM(MILEAGE)

HMD 110

URAT 50

ADODARA 15

Find the locations that have at least one vehicle with manual transmission that has lower mileage than any luxury vehicle at that location.

SELECT VID,MILEAGE,TRANSMISSION FROM VEHICLE WHERE TRANSMISSION = 'MANUAL' AND MILEAGE < (SELECT MILEAGE FROM VEHICLE WHERE VSIZE = 'LUXURY');

Output :

VID MILEAGE TRANSMISSION

V-103 10 MANUAL

Find the last names of people who have at least one reservation at a location such that the number of reservations at that location is less than the number of vehicles at that location with automatic transmission.

SELECT COUNT(VID),LOCATION FROM VEHICLE GROUP BY LOCATION NOT IN (SELECT COUNT(VID),LOCATION FROM VEHICLE GROUP BY LOCATION);

Find average mileage of vehicles for each location, which has at least five vehicles.

SELECT AVG(MILEAGE),COUNT(VID),LOCATION FROM VEHICLE GROUP BY LOCATION HAVING COUNT(VID) >= 5;

Output :

AVG(MILEAGE) COUNT(VID) LOCATION

   36 5 AHMD

Find names of customers whose lastname starts with ‘S’ and who has reserved more vehicles than the customer with CID as 101.

SELECT LAST_NAME,FIRST_NAME FROM CUSTOMERS WHERE LAST_NAME like 'S%';

Delete all the reservations for customer whose last name starts with ‘S’.

DELETE FROM RESERVATION WHERE CID IN (SELECT CID FROM CUSTOMERS WHERE LAST_NAME LIKE 'S%');

Output :

RESERVATION TABLE BEFORE 'DELETE' OPERATION :=====>

CID VID START_DAT END_DATE

101 V-101 10-JAN-01 10-FEB-05

102 V-102 12-MAR-01 10-JUN-06

103 V-103 15-FEB-99 09-SEP-05

105 V-105 15-FEB-03 09-SEP-05

RESERVATION TABLE AFTER 'DELETE' OPERATION :=====>

CID VID START_DAT END_DATE

101 V-101 10-JAN-01 10-FEB-05

102 V-102 12-MAR-01 10-JUN-06

103 V-103 15-FEB-99 09-SEP-05

Add a comment
Know the answer?
Add Answer to:
Create a DDL MYSQL create a database where a user can sell their vehicle, lease a vehicle, financ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use MySQL Workbench for these questions. Do NOT use Lucidchart. MySQL Workbench has more capability than...

    Use MySQL Workbench for these questions. Do NOT use Lucidchart. MySQL Workbench has more capability than Lucidchart, as it allows creation of DDL SQL from the model. Turn in 1 Workbench file , 1 document with the forward-engineered sql statements, and a Word document with your inserted data. This problem mimics the one from the previous assignment. Model it in Workbench, then forward-engineer the database script and import into your database. If the import fails, fix it in the model,...

  • For this set of Review Questions, we will create and use a database for the Wedgewood...

    For this set of Review Questions, we will create and use a database for the Wedgewood Pacific Corporation (WPC) that is similar to the Microsoft Access database we created and used in Chapters 1 and 2. Founded in 1957 in Seattle, Washington, WPC has grown into an internationally recognized organization. The company is located in two buildings. One building houses the Administration, Accounting, Finance, and Human Resources departments, and the second houses the Production, Marketing, and Information Systems departments. The...

  • Your team of consultants has been hired to create a database for MD Employment Agency (MDEA)....

    Your team of consultants has been hired to create a database for MD Employment Agency (MDEA). MDEA is an employment agency that contracts with the city of Miami, FL to assist displaced workers in finding new career opportunities and to help workers currently collecting unemployment benefits. Up to this point MDEA has been using standalone PCs to handle data entry of new clients and to update their status. The company also has relationships with local government agencies that have openings...

  • SQL: The schema name should be mxxws, where mxx is your MySQL user name. To refresh...

    SQL: The schema name should be mxxws, where mxx is your MySQL user name. To refresh your memory – here is the schema for that database: Create the rest of the contact management database by writing the statements that do each of the following items below. For each one: (1) execute them on your copy of the database, and (2) write the statements in the space: Statement to create the Contact table (one statement) Statement to create the Employee table...

  • Help with database creation - create a visio ER diagram of the scenerio below.. thanks The...

    Help with database creation - create a visio ER diagram of the scenerio below.. thanks The registrar's office at Weber State University wants you to create a new database to support an future application that will help their department better keep track of the scheduled classes offered each semester, including the specific course sections and lecturers appearing in the schedule, and the students registering for courses according to the published schedule. Courses (think course catalog) may or may not be...

  • Consider the database schema of college database. Students have a major department and take classes where...

    Consider the database schema of college database. Students have a major department and take classes where faculty can be met. Student (cwid int, name, text, age int, majorDept text) Department (name text, chair text) Faculty (name text, deptName text) Enrollment (facName text, studID int) Note that the underlined attributes are primary keys. studID, chair, deptName of Faculty, facName and majorDept of Student are foreign keys to cwid, name of Faculty, name of Department, name of Faculty and also name of...

  • Create a series of ER Diagrams using MySQL Workbench. Each question below is a different version...

    Create a series of ER Diagrams using MySQL Workbench. Each question below is a different version of the same database, with each version increasing in complexity. You need to submit an ER diagram for each version, in pdf or png format. The easiest would be to export your diagrams as png format and insert them into an MS Word document. For each ER diagram clearly indicate primary keys, foreign keys, and relationships, including cardinality (i.e. 1-to-many). Indicate in your diagram...

  • database and sql problme THE QUESTIONS 3, 4,5 and 6 REFER TO THE RELATIONAL TABLES LISTED...

    database and sql problme THE QUESTIONS 3, 4,5 and 6 REFER TO THE RELATIONAL TABLES LISTED BELOW CREATE TABLE Department ( DECIMAL(5) VARCHAR(30) CHAR(5) DATE NOT NULL NOT NULL NOT NULL * Department number /*Department name * Department manager number */ /Manager start date DNumber DName Manager MSDate CONSTRAINT Department_PK PRIMARY KEY(DNumber) CONSTRAINT Department_CK UNIQUE(DName) CREATE TABLE DeptLocation DECIMAL(5) VARCHAR(50) NOT NULL NOT NULL DNumber * Department number */ * Department location */ Address CONSTRAINT DeptLocation_PK PRIMARY KEY(DNumber, Address) CONSTRAINT...

  • You are a database consultant with Ace Software, Inc., and have been assigned to develop a...

    You are a database consultant with Ace Software, Inc., and have been assigned to develop a database for the Mom and Pop Johnson video store in town. Mom and Pop have been keeping their records of videos and DVDs purchased from distributors and rented to customers in stacks of invoices and piles of rental forms for years. They have finally decided to automate their record keeping with a relational database. You sit down with Mom and Pop to discuss their...

  • 484 Core Concepts of Accounting Information Systems a. Using Access, create an employee table sim- ilar...

    484 Core Concepts of Accounting Information Systems a. Using Access, create an employee table sim- ilar to the one shown in Figure 15-4. Create created. (Hint You can use the aforemen- tioned expression for the department code as a validation rule.) at least one record for this table b. Create validation rules for the listed restric tions and an accompanying validation text for each. Document your work by provid- ing a table outlining exactly what rules you c. Test each...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT