How to create tables, sequences, and indexes Exercises Write a script that adds an index to the order_date column in the Orders table in the mgs schema. Write a script that implements the following design: In the Downloads table, the user_id and product_id columns are the foreign keys. Create these tables in the ex schema. Create the sequences for the user_id, download_id, and product_id columns. Include a PL/SQL script to drop the table or sequence if it already exists. 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. 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 SYSDATE function to insert the current date into the download_date column. Use the sequences created in the previous exercise to get the values for the user_id, download_id, and product_id columns. 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.   Write an ALTER TABLE statement that adds two new columns to the Products table created in exercise 2. Add one column for product price that provides for three digits to the left of the decimal point and two to the right. This column should have a default value of 9.99. Add one column for the date and time that the product was added to the database. Write an ALTER TABLE statement that modifies the Users table created in exercise 2 so the first_name column can store NULL values and can store a maximum of 20 characters. Code an UPDATE statement that inserts a NULL value into this column. It should work since this column now allows NULL values. Code another UPDATE statement that attempts to insert a first name that’s longer than 20 characters. It should fail due to the length of the colum

A Guide to SQL
9th Edition
ISBN:9781111527273
Author:Philip J. Pratt
Publisher:Philip J. Pratt
Chapter7: Database Administration
Section: Chapter Questions
Problem 4TD: Write, but do not execute, the commands to grant the following privileges: a. User Ashton must be...
icon
Related questions
Question

How to create tables, sequences,
and indexes

Exercises

  1. Write a script that adds an index to the order_date column in the Orders table in the mgs schema.
  2. Write a script that implements the following design:

In the Downloads table, the user_id and product_id columns are the foreign keys.

Create these tables in the ex schema.

Create the sequences for the user_id, download_id, and product_id columns.

Include a PL/SQL script to drop the table or sequence if it already exists.

Include any indexes that you think are necessary.

  1. Write a script that adds rows to the database that you created in exercise 2.

Add two rows to the Users and Products 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 SYSDATE function to insert the current date into the download_date column.

Use the sequences created in the previous exercise to get the values for the user_id, download_id, and product_id columns.

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.

 

  1. Write an ALTER TABLE statement that adds two new columns to the Products table created in exercise 2.

Add one column for product price that provides for three digits to the left of the decimal point and two to the right. This column should have a default value of 9.99.

Add one column for the date and time that the product was added to the database.

  1. Write an ALTER TABLE statement that modifies the Users table created in exercise 2 so the first_name column can store NULL values and can store a maximum of 20 characters.

Code an UPDATE statement that inserts a NULL value into this column. It should work since this column now allows NULL values.

Code another UPDATE statement that attempts to insert a first name that’s longer than 20 characters. It should fail due to the length of the column.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
SQL Query
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
A Guide to SQL
A Guide to SQL
Computer Science
ISBN:
9781111527273
Author:
Philip J. Pratt
Publisher:
Course Technology Ptr
Oracle 12c: SQL
Oracle 12c: SQL
Computer Science
ISBN:
9781305251038
Author:
Joan Casteel
Publisher:
Cengage Learning
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage