Write a script that adds an index to the my_guitar_shop database for the zip cod
ID: 3827351 • Letter: W
Question
Write a script that adds an index to the my_guitar_shop database for the zip code field in the Customers table (screenshot). Write a script that implements the following design in a database named my_web_db (screenshot of SQL code to create the database and table and EER diagram): in the Downloads table, the user_id and product_id columns are the foreign keys. Include a statement to drop the database if it already exists. Include statements to create and select the database. Include any indexes that you think are necessary. Write a script that adds rows to the database that you created in exercise 2. Add two rows to the Users and Products tables (screenshot both tables). Add three rows to the Downloads table: one row for user 1 and product 2; one row for user 2 and product 1; and one row for user 2 and product 2. Use the NOW function to insert the current date and time into the download_date column (screenshot). Write a SELECT statement that joins the three tables and retrieves the data from these tables like this: Sort the results by the email address in descending sequence and the product name in ascending sequence (screenshot).Explanation / Answer
Please find below the answers:
1.CREATE INDEX cust_guitar_zip ON Customers(zip_code);
2. To drop database:
DROP DATABASE my_web_db;
To create database:
CREATE DATABASE my_web_db-;
3.
Insert into Users values ('User1','a@a.com','a','s');
Insert into Users values ('User2','a1@a.com','a1','s');
Insert into products values ('Product1', 'A');
Insert into products values ('Product2', 'A1');
Insert into downloads values('1','User1','24-Jan-2017' ,'a.txt' ,'Product2');
Insert into downloads values('2','User2','25-Jan-2017' , 'b.txt','Product1');
Insert into downloads values('3','User2', '26-Jan-2017', 'c.txt','Product2');
Select u.email_address, u.first_name,u.last_name,d.download_date, d.filename, p.product_name from users u INNER JOIN downloads d on u.user_id=d.user_id INNER JOIN products p on d.product_id=p.product_id
-- For Sorting use :
-- order by u.email_address desc
-- order by p.product_namr (by default its asc)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.