Question

In: Computer Science

Please create the following tables for a tool rental database with appropriate primary keys & foreign...

Please create the following tables for a tool rental database with appropriate

primary keys & foreign keys.

Assumptions:

1. Each tool belongs to a category.

2. Each category may have a parent category but the parent category should not have

a parent category (so at most two levels). E.g., a Tool A belongs to the electric mower,

and electric mowers belong to mowers. Mower has no parent category.

3. Each tool can be rented at different time units. The typical time units are hourly,

daily, and weekly. There is a different price for each time unit and tool

combination. E.g., tool A may be rented at $5 per hour, $30 per day, and $120 per

week.

4. Each customer can rent a tool for a certain number of time units. If the tool is

returned late a late fee will be charged.

The list of tables is:

Cust_Table:

cid, -- customer id

cname, --- customer name

cphone, --- customer phone

cemail, --- customer email

Category_Table:

ctid, --- category id

ctname, --- category name

parent, --- parent category id since category has a hierarchy structure, power washers,

electric power washers, gas power washers. You can assume that there are only two

levels.

Tool_Table:

tid, --- tool id

tname, --- tool name

ctid, --- category id, the bottom level.

quantity, --- number of this tools

Time_Unit_Table allowed renting unit

tuid, --- time unit id

len, --- length of period, can be 1 hour, 1 day, etc.

min_len, --- minimal #of time unit, e.g., hourly rental but minimal 4 hours.

Tool_Price:

tid, --- tool id

tuid, --- time unit id

price, -- price per period

Rental_Table:

rid, --- rental id

cid, --- customer id

tid, --- tool id

tuid, --- time unit id

num_unit, --- number of time unit of rental, e.g., if num_unit = 5 and unit is hourly, it

means 5 hours.

start_time, -- rental start time

end_time, --- suppose rental end_time

return_time, --- time to return the tool

credit_card, --- credit card number

total, --- total charge

- Insert at least three rows of data to each table. Make sure you keep the

primary key and foreign key constraints.

-Write an anonymous PL/SQL program to compute the sum of 2, 4, 6, 8, 10.

You must use a loop. Tip: consider how to update your loop variable.

- Print out the estimated charge for rental ID 1 if the customer returns the tool in

time. The charge is computed by the price in the price_tool table * number of units the

customer plans to rent. E.g., if a customer rents a tool hourly for 5 hours, and the hourly rate for the tool is $6, the estimated charge should be $30.

Solutions

Expert Solution

Hello, I am adding comments and sample output for better and clear understanding. Please find the answer attached below. THANK YOU.


/* Creating Cust_table */
CREATE TABLE Cust_table(cid integer PRIMARY KEY, cname varchar(20),cphone int,cemail varchar(40));
/* Cust_table do not have any foreign key*/
/* Creating a record in this table */
INSERT INTO Cust_table VALUES(1,'Tom',994571855,'[email protected]');



/* Creating Category_table */
CREATE TABLE Category_table(ctid integer PRIMARY KEY, ctname varchar(20),parent varchar(30));
/* category_table do not have any foreign key*/
/* Creating a record in this table */
INSERT INTO Category_table VALUES(501,'electric motor','motor');



/* Creating tool_table */
CREATE TABLE tool_table(tid integer PRIMARY KEY, tname varchar(20),quantity integer,ctid integer references Category_table(ctid));
/* Creating a record in this table */
INSERT INTO tool_table VALUES(10,'A_motor',1,12);



/* Creating time_unit_table */
CREATE TABLE time_unit_table(tuid integer PRIMARY KEY, len varchar(10),Min_length varchar(10));
/* Creating a records in this table */
INSERT INTO time_unit_table VALUES(101,'1day','3 hours');


/* Creating tool_price_table */
CREATE TABLE tool_price_table(tid integer PRIMARY KEY references tool_table(tid), tuid integer references time_unit_table(tuid),price integer);
/* tid and tuid are foreign keys*/
/* Creating a records in this table */
INSERT INTO tool_price_table VALUES(201,101,5);


/* Creating rental_table */
CREATE TABLE rental_table(rid integer PRIMARY KEY,cid integer references Cust_table(cid),tid integer references tool_table(tid),tuid integer references time_unit_table(tuid),num_unit integer, start_time time,end_time time,return_time time,credit_card integer,total integer );
/* tid and tuid are foreign keys*/
/* Creating a records in this table */
INSERT INTO rental_table VALUES(401,501,201,101,51,"10:2:30","13:2:30","15:22:02",1589785,150);



/* Give command "show tables" after creating all 
these tables to get the structure of each of the table */

/* Display all the records from all the table using the following commands */

SELECT * FROM Cust_table;

SELECT * FROM Category_table;

SELECT * FROM tool_table;

SELECT * FROM time_unit_table;

SELECT * FROM tool_price_table;

SELECT * FROM rental_table;

/* after executing all the select statements we will get the following output */

1|Tom|994571855|[email protected]
501|electric motor|motor
10|A_motor|1|12
101|1day|3 hours
201|101|5
401|501|201|101|51|10:2:30|13:2:30|15:22:02|1589785|150








Related Solutions

Problem 1. Please create the following tables for a tool rental database with appropriate primary keys...
Problem 1. Please create the following tables for a tool rental database with appropriate primary keys & foreign keys. [30 points] Assumptions: Each tool belongs to a category. Each category may have a parent category but the parent category should not have parent category (so at most two levels). E.g., a Tool A belongs to electric mower, and electric mower belongs to mower. Mower has no parent category. Each tool can be rented at different time units. The typical time...
Create a Database Schema for a hotel reservation system. indicate the Primary Keys, Foreign Keys, and...
Create a Database Schema for a hotel reservation system. indicate the Primary Keys, Foreign Keys, and the one-to-one or one-to-many relationships between the tables. Also describe in a small paragraph the scope of the back-end database, by explaining the different tables and their relations in your schema.
Consider the following three tables, primary and foreign keys. Table Name        SalesPeople Attribute Name                  &nbsp
Consider the following three tables, primary and foreign keys. Table Name        SalesPeople Attribute Name                                Type                                      Key Type EmployeeNumber             Number                               Primary Key Name                                   Character JobTitle                                  Character            Address                                 Character PhoneNumber                     Character YearsInPosition                             Number Table Name        ProductDescription Attribute Name                                Type                                      Key Type                 ProductNumber                Number                               Primary Key                 ProductName                  Character                            ProductPrice                   Number Table Name        SalesOrder Attribute Name                                Type                                      Key Type                 SalesOrderNumber        Number                               Primary Key                 ProductNumber               Number                               Foreign Key                 EmployeeNumber           Number                               Foreign Key                 SalesOrderDate                Date Assume that you...
Database Design CIW State_Capitals Physical Database Create primary and secondary keys for the attached unfinished physical...
Database Design CIW State_Capitals Physical Database Create primary and secondary keys for the attached unfinished physical database design. CREATE DATABASE STATE_CAPITALS; GO USE STATE_CAPITALS; GO CREATE TABLE Country( Country_Code varchar(10) NOT NULL, Country_Name varchar(50) NOT NULL, Population int NOT NULL, Country_Size float NOT NULL ) GO CREATE TABLE Region( Country_Code varchar(10) NOT NULL, Region_Code varchar(10) NOT NULL, Region_Name varchar(50) NOT NULL ) GO CREATE TABLE State( Region_Code varchar(10) NOT NULL, State_Code char(2) NOT NULL, State_Name varchar(50) NOT NULL, Date_of_Statehood int...
Consider the following relational schema about a University (the primary keys are underlined and foreign keys...
Consider the following relational schema about a University (the primary keys are underlined and foreign keys are italic) STUDENT(StudentID, name, major, year, age) CLASS(ClassName, meetsAt, room, LecturerID) ENROLLED(StudentID, ClassName, mark) LECTURER(LecturerID, name, DepartmentID) DEPARTMENT(DepartmentID, name) Write the SQL statements for the following query: B1. Find the age of the oldest student. B2. Find the ID’s of lecturers whose name begins with “K” \ B3. Find the age of the youngest student who is enrolled in Mechatronics. B4. Find the age...
In the world of database design and building it is very important to define Primary keys...
In the world of database design and building it is very important to define Primary keys in each table. The text this week talks about primary keys. What are they and why are they so important to a properly functioning database?
Database exercise: inpatient cases Create database using name RUMKIT Create tables below in that database patient(idPatient,...
Database exercise: inpatient cases Create database using name RUMKIT Create tables below in that database patient(idPatient, fullName, biologicalMother, birthdate, address) doctor(idDr, fullName, specialization, consulRates) inpatient(idPatient, entryTime, outTime, idDr, idRoom). Please make entryTime as column that is going to be filled automatically when care record is being add room(idRoom, roomName, cost) fill the data above to each table Create sql query and relational algebra expressions for the query Please give me detailed answer so I could learn from it. Thank you...
Consider the database of a car rental company that contains three tables drivers, cars and reservation...
Consider the database of a car rental company that contains three tables drivers, cars and reservation tables. Drivers:                                           Reservation:                              Cars: Dno Dname age Dno Cno Day Cno Cmake Color 22 Dustin 45 22 101 10/10 101 BMW Blue 29 Brutus 33 22 102 10/10 102 VW Red 31 Lubber 55 22 103 10/8 103 OPEL Green 32 Andy 25 22 104 10/7 104 FIAT Red 58 Rusty 35 31 102 11/10 64 Horatio 35 31 103 11/6 71 Zorba...
Consider the database of a car rental company that contains three tables drivers, cars and reservation...
Consider the database of a car rental company that contains three tables drivers, cars and reservation tables. Drivers:                                           Reservation:                              Cars: Dno Dname age Dno Cno Day Cno Cmake Color 22 Dustin 45 22 101 10/10 101 BMW Blue 29 Brutus 33 22 102 10/10 102 VW Red 31 Lubber 55 22 103 10/8 103 OPEL Green 32 Andy 25 22 104 10/7 104 FIAT Red 58 Rusty 35 31 102 11/10 64 Horatio 35 31 103 11/6 71 Zorba...
Using your downloaded DBMS (MS SQL Server), create a new database. Create the database tables based...
Using your downloaded DBMS (MS SQL Server), create a new database. Create the database tables based on your entities defining The attributes within each table The primary and foreign keys within each table *****Show your database tables, tables attributes, primary and foreign keys***** Do not forget to check the lesson slides and videos that show you how to convert an ER/EER into a database schema, and how to create a database and tables using MS SQL Server.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT