Question

In: Computer Science

Please submit SQL statements as a plain text file (.txt). If blackboard rejects txt file you...

Please submit SQL statements as a plain text file (.txt). If blackboard rejects txt file you can submit a zipped file containing the text file. Word, PDF, or Image format are not accepted. You do not need to show screen shot. Make sure you have tested your SQL statements in Oracle 11g.

Problem 1. Please create the following tables for a tool rental database with appropriate primary keys & foreign keys. [30 points]

Assumptions:

  1. Each tool belongs to a category.
  2. 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.
  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:

Tables:

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:

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:

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

Solutions

Expert Solution

We are not allowed to attach any file while answering. I can either upload an image or paste the contents. So please find below the SQL statements.

CREATE TABLE cust (
   cid varchar(50) NOT NULL,
   cname varchar(50) NULL,
   cphone varchar(15) NULL,
   cemail varchar(50) NULL,
   CONSTRAINT cust_pk PRIMARY KEY (cid)
);


CREATE TABLE category (
   ctid varchar(50) NOT NULL,
   ctname varchar(50) NULL,
   parent varchar(50) NULL,
   CONSTRAINT category_pk PRIMARY KEY (ctid)
);


CREATE TABLE tool (
   tool_id varchar(50) NOT NULL,
   tname varchar(50) NULL,
   ctid varchar(50) NULL,
   quantity float(10) NULL,
   CONSTRAINT tool_pk PRIMARY KEY (tool_id),
   CONSTRAINT tool_fk FOREIGN KEY (ctid) REFERENCES category(ctid)
);


CREATE TABLE time_unit (
   tuid int NOT NULL,
   len varchar(10) NULL,
   min_len varchar(10) NULL,
   CONSTRAINT time_unit_pk PRIMARY KEY (tuid)
);


CREATE TABLE tool_price (
   tid varchar(50) NOT NULL,
   tuid int NOT NULL,
   price float NULL,
   CONSTRAINT tool_price_fk FOREIGN KEY (tid) REFERENCES tool(tool_id),
   CONSTRAINT tool_price_fk_1 FOREIGN KEY (tuid) REFERENCES time_unit(tuid)
);

CREATE TABLE rental (
   rid int NOT NULL,
   cid varchar(50) NULL,
   tid varchar(50) NULL,
   tuid int NULL,
   num_unit int NULL,
   start_time timestamp NULL,
   end_time timestamp NULL,
   return_time timestamp NULL,
   credit_card int NULL,
   total float NULL,
   CONSTRAINT rental_pk PRIMARY KEY (rid),
   CONSTRAINT rental_fk FOREIGN KEY (cid) REFERENCES cust(cid),
   CONSTRAINT rental_fk_1 FOREIGN KEY (tid) REFERENCES tool(tool_id),
   CONSTRAINT rental_fk_2 FOREIGN KEY (tuid) REFERENCES time_unit(tuid)
);



Related Solutions

Please submit SQL statements as a plain text file (.txt). If blackboard rejects txt file you...
Please submit SQL statements as a plain text file (.txt). If blackboard rejects txt file you can submit a zipped file containing the text file. Word, PDF, or Image format are not accepted. You do not need to show screen shot. Make sure you have tested your SQL statements in Oracle 11g. The list of tables is: Tables: Cust Table: cid, -- customer id cname, --- customer name cphone, --- customer phone cemail, --- customer email Category table: ctid, ---...
The file CO2.txt, found on Blackboard with this assignment, contains 50 numbers, which represent the concentration...
The file CO2.txt, found on Blackboard with this assignment, contains 50 numbers, which represent the concentration of atmospheric carbon dioxide (parts per million) recorded at Mauna Loa, HI. The data in the file are the CO2 values on May 15th of each year from 1961 through 2010, (with background level CO2 removed). Fit an exponential model. Use the model to predict the CO2 value for May 15, 2015. Print the result to the screen using fprintf. The actual value was...
Create one sql script file to complete the following. You cannot run separate SQL statements for...
Create one sql script file to complete the following. You cannot run separate SQL statements for the homework. You will also need to place a semicolon after each SQL statement, a requirement for SQL files containing multiple SQL statements Lesson 3 Write a query to display the current date. Label the column DATE. Display the last name of all employees who have an A and an E in their last name. For each employee, display the employee number, last_name, salary,...
Exercise 2: You are provided with a text file named covid19-3.txt. It reports a few confirmed...
Exercise 2: You are provided with a text file named covid19-3.txt. It reports a few confirmed cases of covid19. It consists of three columns. The 1st column indicates the names of the provinces, the 2nd column indicates the names of the countries and the 3rd column indicates the numbers of confirmed cases. To do: 1. Define a function that reads, from covid19-3.txt, provinces, countries and confirmed cases in three separate lists. 2. Define a function that iterates through a list...
For Assignment 2, submit a word or pdf file with the SQL queries along with screenshots...
For Assignment 2, submit a word or pdf file with the SQL queries along with screenshots of the outputs. (It is ok if the whole problem cannot be answered, if possible, I just would like an idea of how to begin, thanks in advance!) 9. Write a query to count the number of invoices. 10. Write a query to count the number of customers with a balance of more than $500. 11. Generate a listing of all purchases made by...
Python class Select a free ebook on gutenberg . org and download the plain text file...
Python class Select a free ebook on gutenberg . org and download the plain text file (utf8). the ebook is (The Devil's Dictionary by Ambrose Bierce) Write a program that does the following: Read in your ebook (any book, any language) Break the book into words (look at .split() for strings) Make a dictionary of all words and how often they occur: for instance if the word'the'happened 2000 time and the word'a' happened 1940 times word_dict= {'the' : 2000, 'a'...
A text file called coit20245.txt consists of N lines each containing a name and a family...
A text file called coit20245.txt consists of N lines each containing a name and a family name as follows. N is largest digit of your student id number. Example of coit20245.txt file: Daniel Atkinson Rob Jackson Brian Lara Write a main() method that reads the rows of coit20245.txt and counts the lines which starts with a first letter of your name. You are to provide class comments that describe what the application does. You are also to provide comments that...
Use Python to Complete the following on a single text file and submit your code and...
Use Python to Complete the following on a single text file and submit your code and your output as separate documents. For each problem create the necessary list objects and write code to perform the following examples: Sum all the items in a list. Multiply all the items in a list. Get the largest number from a list. Get the smallest number from a list. Remove duplicates from a list. Check a list is empty or not. Clone or copy...
Python class Select a free ebook and download the plain text file (utf8). Write a program...
Python class Select a free ebook and download the plain text file (utf8). Write a program that does the following: Read in your ebook (any book, any language) Break the book into words (look at .split() for strings) Make a dictionary of all words and how often they occur: for instance if the word'the' happened 2000 time and the word'a' happened 1940 times word_dict= {'the' : 2000, 'a' :1940} Print the dictionary of word frequencies to a file (freqs.txt) with...
using JUPYTER notebook: 9.1 (Class Average: Writing Grades to a Plain Text File) Figure 3.2 presented...
using JUPYTER notebook: 9.1 (Class Average: Writing Grades to a Plain Text File) Figure 3.2 presented a classaverage script in which you could enter any number of grades followed by a sentinel value, then calculate the class average. Another approach would be to read the grades from a file. In an IPython session, write code that enables you to store any number of grades into a grades.txt plain text file. In an IPython session, write code that reads the grades...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT