Question

In: Computer Science

SQL Homework -- This script creates the schema named mgs -- Connect as the user named...

SQL Homework -- This script creates the schema named mgs -- Connect as the user named mgs --CONNECT cs270226mgs/mgs; -- Use an anonymous PL/SQL script to -- drop all tables and sequences in the current schema and -- suppress any error messages that may displayed -- if these objects don't exist BEGIN EXECUTE IMMEDIATE 'DROP SEQUENCE category_id_seq'; EXECUTE IMMEDIATE 'DROP SEQUENCE product_id_seq'; EXECUTE IMMEDIATE 'DROP SEQUENCE customer_id_seq'; EXECUTE IMMEDIATE 'DROP SEQUENCE address_id_seq'; EXECUTE IMMEDIATE 'DROP SEQUENCE order_id_seq'; EXECUTE IMMEDIATE 'DROP SEQUENCE item_id_seq'; EXECUTE IMMEDIATE 'DROP SEQUENCE admin_id_seq'; EXECUTE IMMEDIATE 'DROP TABLE administrators'; EXECUTE IMMEDIATE 'DROP TABLE order_items'; EXECUTE IMMEDIATE 'DROP TABLE orders'; EXECUTE IMMEDIATE 'DROP TABLE products'; EXECUTE IMMEDIATE 'DROP TABLE categories'; EXECUTE IMMEDIATE 'DROP TABLE addresses'; EXECUTE IMMEDIATE 'DROP TABLE customers'; -- EXECUTE IMMEDIATE 'DROP TABLE author'; EXECUTE IMMEDIATE 'DROP TABLE bookauthor'; EXECUTE IMMEDIATE 'DROP TABLE books'; EXECUTE IMMEDIATE 'DROP TABLE order_items'; EXECUTE IMMEDIATE 'DROP TABLE orderitems'; EXECUTE IMMEDIATE 'DROP TABLE orders'; EXECUTE IMMEDIATE 'DROP TABLE promotion'; EXECUTE IMMEDIATE 'DROP TABLE publisher'; EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE(''); END; / -- Create the tables CREATE TABLE categories ( category_id NUMBER PRIMARY KEY, category_name VARCHAR2(255) NOT NULL UNIQUE ); CREATE TABLE products ( product_id NUMBER PRIMARY KEY, category_id NUMBER REFERENCES categories (category_id), product_code VARCHAR2(10) NOT NULL UNIQUE, product_name VARCHAR2(255) NOT NULL, description VARCHAR2(1500) NOT NULL, list_price NUMBER(10,2) NOT NULL, discount_percent NUMBER(10,2) DEFAULT 0.00, date_added DATE DEFAULT NULL ); CREATE TABLE customers ( customer_id NUMBER PRIMARY KEY, email_address VARCHAR2(255) NOT NULL UNIQUE, password VARCHAR2(60) NOT NULL, first_name VARCHAR2(60) NOT NULL, last_name VARCHAR2(60) NOT NULL, shipping_address_id NUMBER DEFAULT NULL, billing_address_id NUMBER DEFAULT NULL ); CREATE TABLE addresses ( address_id NUMBER PRIMARY KEY, customer_id NUMBER REFERENCES customers (customer_id), line1 VARCHAR2(60) NOT NULL, line2 VARCHAR2(60) DEFAULT NULL, city VARCHAR2(40) NOT NULL, state VARCHAR2(2) NOT NULL, zip_code VARCHAR2(10) NOT NULL, phone VARCHAR2(12) NOT NULL, disabled NUMBER(1) DEFAULT 0 ); CREATE TABLE orders ( order_id NUMBER PRIMARY KEY, customer_id NUMBER REFERENCES customers (customer_id), order_date DATE NOT NULL, ship_amount NUMBER(10,2) NOT NULL, tax_amount NUMBER(10,2) NOT NULL, ship_date DATE DEFAULT NULL, ship_address_id NUMBER NOT NULL, card_type VARCHAR2(50) NOT NULL, card_number CHAR(16) NOT NULL, card_expires CHAR(7) NOT NULL, billing_address_id NUMBER NOT NULL ); CREATE TABLE order_items ( item_id NUMBER PRIMARY KEY, order_id NUMBER REFERENCES orders (order_id), product_id NUMBER REFERENCES products (product_id), item_price NUMBER(10,2) NOT NULL, discount_amount NUMBER(10,2) NOT NULL, quantity NUMBER NOT NULL ); CREATE TABLE administrators ( admin_id NUMBER PRIMARY KEY, email_address VARCHAR2(255) NOT NULL, password VARCHAR2(255) NOT NULL, first_name VARCHAR2(255) NOT NULL, last_name VARCHAR2(255) NOT NULL ); -- Disable substitution variable prompting SET DEFINE OFF; -- Insert data into the tables INSERT INTO categories (category_id, category_name) VALUES (1, 'Guitars'); INSERT INTO categories (category_id, category_name) VALUES (2, 'Basses'); INSERT INTO categories (category_id, category_name) VALUES (3, 'Drums'); INSERT INTO categories (category_id, category_name) VALUES (4, 'Keyboards'); CREATE SEQUENCE category_id_seq START WITH 5; 1. Draw a database diagram for the script file named create_mgs_tables.sql that’s in the mgs_ex_starts folder.

2. Draw a database diagram for a database that stores information about the downloads that users make. Each user must have an email address, first name, and last name. Each user can have one or more downloads. Each download must have a filename and download date/time. Each product can be related to one or more downloads. Each product must have a name.

Solutions

Expert Solution

1.

2.


Related Solutions

SQL Code: Write a script that creates and calls a stored procedure named test. This procedure...
SQL Code: Write a script that creates and calls a stored procedure named test. This procedure should identify all of the prime numbers less than 100. (A prime number is an integer that can't be divided by another integer other than 1 and itself.) Then, it should display a string variable that includes the prime numbers like this: 2 1 3 1 5 1 7 1 1 1 1 1 3 1 1 7 1 1 9 1 2 3...
Write a script named numberlines.py. This script creates a program listing from a source program. This...
Write a script named numberlines.py. This script creates a program listing from a source program. This script should: Prompt the user for the names of two files. The input filename could be the name of the script itself, but be careful to use a different output filename! The script copies the lines of text from the input file to the output file, numbering each line as it goes. The line numbers should be right-justified in 4 columns, so that the...
write a script named compute.sh that is used to do simple arithmetic for the user. There...
write a script named compute.sh that is used to do simple arithmetic for the user. There should be no command line arguments. Instead, all values from the user should be prompted for and read in to the script using the read command. Specifically, you need to ask the user for two integers and an operation string. The operation should be "add", "sub", "mul", "div", or "exp", for addition, subtraction, multiplication, division, and exponentiation, respectively. Your script should take the two...
Write a script that creates and calls a stored procedure named test. This procedure should identify...
Write a script that creates and calls a stored procedure named test. This procedure should identify all of the prime numbers less than 100. (A prime number is an integer that can't be divided by another integer other than 1 and itself.) Then, it should display a string variable that includes the prime numbers like this: 2 1 3 1 5 1 7 1 1 1 1 1 3 1 1 7 1 1 9 1 2 3 1 2...
Developer User Account Create a user account using T-SQL for developers named DEVELOPER with the password...
Developer User Account Create a user account using T-SQL for developers named DEVELOPER with the password TESTACCOUNT that grants the user the ability to: Select and modify any table. Connect to and have access to all resources. In SSMS
Listed below is the relational database schema for an online store(SQL/Java): MEMBER(last_name, first_name, email, password, user,street,...
Listed below is the relational database schema for an online store(SQL/Java): MEMBER(last_name, first_name, email, password, user,street, city, state, zip, card_type, card_no, expiration, name_on_card) book_SALE(listing_no, seller, isbn, condition, price) ORDERS(order_no, buyer, order_date, tot) ITEM(order_no, listing_no) BOOK(isbn, title, author, edition, publisher, keywords) The bold attribute(s) in a relation is the primary key of that relation. The italized attributes in some relations denote foreign keys. The seller attribute in the book_SALE relation is a foreign key to the user attribute in the MEMBER...
Listed below is the relational database schema for an online store(SQL/Java): MEMBER(last_name, first_name, email, password, user,street,...
Listed below is the relational database schema for an online store(SQL/Java): MEMBER(last_name, first_name, email, password, user,street, city, state, zip, card_type, card_no, expiration, name_on_card) book_SALE(listing_no, seller, isbn, condition, price) ORDERS(order_no, buyer, order_date, tot) ITEMS(order_no, listing_no) BOOK(isbn, title, author, edition, publisher, keywords) The bold attribute(s) in a relation is the primary key of that relation. The italized attributes in some relations denote foreign keys. Create/Define the table.
Basic SQL Use the following schema to answer the queries below using SQL DEVICE [dno, dtype,...
Basic SQL Use the following schema to answer the queries below using SQL DEVICE [dno, dtype, price] PROVIDER [pno, pname, web] SERVICE [dno, pno, servicedate] SERVICE.dno references DEVICE.dno SERVICE.pno references PROVIDER.pno bold is underline. a) Find the dno for the most expensive device b) Find all providers that have the work fast in the name c) Find the number of different device types (dtype) d) Give all details of devices with price more than $400
Write a bash script that... create new user ./finalProject user if a new user is to...
Write a bash script that... create new user ./finalProject user if a new user is to be created ask for the new users information and use it when creating the new user add a new printer ./finalProject printer ask anything you need in order to create the new printer (I.e. name) permissions ./finalProject permissions ask what document and permissions the user wants restarting the computer ./finalProject restart
Write a complete shell script that first asks the user to enter a URL. The script...
Write a complete shell script that first asks the user to enter a URL. The script should read the URL into a variable named url. The shell script should then retrieve the file associated with the URL by using the curl command. The output of the curl command should be redirected to a file named html_file. The shell script should then use the grep command to search the file named html_file for the word manhattan. Finally, the shell script should...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT