Some large cities (e.g., Cologne Germany) have started a project called car shar
ID: 3674349 • Letter: S
Question
Some large cities (e.g., Cologne Germany) have started a project called car sharing to reduce the number of cars in the city and also to reduce the cost of having a car available when needed by a person. One car is partially owned by several People. The number of owners per car may vary. Typically, not more than four people own one particular car. Also, each person can own a different percentage of the car, depending on how often she uses the car. Each person might own a share of more than one car. Obviously, only one person can use the car at any particular time. Thus, a database is needed to keep track of reservation made for the car. Write SQL to create the database for the following data model. Be sure to specify primary and foreign keys.Explanation / Answer
SQL> CREATE TABLE CAR(CARID VARCHAR2(10) PRIMARY KEY, CARMAKE VARCHAR2(15), CARMODEL VARCHAR2(10), CARTAG VARCHAR2(10), CARINSURANCE VARCHAR2(10));
SQL> CREATE TABLE OWNER(OWNERID VARCHAR2(10) PRIMARY KEY, OLNAME VARCHAR2(10), OFNAME VARCHAR2(10));
SQL> CREATE TABLE OWNERSHIP(CARID VARCHAR2(10) REFERENCES CAR(CARID),
OWNERID VARCHAR2(10) REFERENCES OWNER(OWNERID),
PERCENTAGE NUMBER(5,2),
PRIMARY KEY(CARID, OWNERID));
SQL> CREATE TABLE RESERVATION(CARID VARCHAR2(10) REFERENCES CAR(CARID),
OWNERID VARCHAR2(10) REFERENCES OWNER(OWNERID),
RESV_BEG_DATE DATE, RESV_BEG_TIME TIME,
RESV_END_DATE DATE, RESV_END_TIME TIME);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.