Answered step by step
Verified Expert Solution
Question
1 Approved Answer
How to create and maintain a database with SQL Exercises 1 . Write a script that adds an index to the MyGuitarShop database for the
How to create and maintain a database with
SQL
Exercises
Write a script that adds an index to the MyGuitarShop database for the zip code
field in the Addresses
table.
Write a script that implements the following design to create a database named
MyWebDB:
Include a statement to drop the MyWebDB database if it already exists.
Include statements to create and select the MyWebDB database.
In the Downloads table, the UserID and ProductID columns are foreign keys.
Choose appropriate data types for each column in the tables. Hint: Use the int,
varchar, and
datetime data types.
Define the EmailAddress and ProductName columns so that each value must be
unique.
In the Users table, the EmailAddress and LastName columns are required, but the
FirstName column
is not.
Include any indexes that you think are necessary.
Write a script that adds rows to the database that you created in STEP
Add two rows to the Users table and two rows to the Products table. You can
choose any names you
like or use names that return the same results as in the example table below.
Add three rows to the Downloads table: one row for user and product ; one for
user and product
; and one for user and product Use the GETDATE function to insert the current
date and time
into the DownloadDate column.
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 order and the product name in
ascending order.
Write a script that uses ALTER TABLE statements to add the following new
columns to the Products
table created in STEP :
Add one column for product price that provides for up to three digits to the left of the
decimal point
and two to the right. This column should have a default value of
Add one column for the date and time that the product was added to the database.
Write a script that uses an ALTER TABLE statement to modify the Users table
created in STEP
so the FirstName column cannot store null values and can store a maximum of
characters.
In the same script, code an UPDATE statement that attempts to insert a row with a
null value in the FirstName column. It should fail due to the new not null constraint.
Code another UPDATE statement that attempts to insert a first name thats longer
than characters.
It should fail due to the length of the column
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started