Chapter 5 Solution

$30.00

Category: Tag:

Description

How to insert, update, and delete data

Exercises

To test whether a table has been modified correctly as you do these exercises, you can write and run an appropriate SELECT statement.

  1. Write an INSERT statement that adds this row to the Categories table:

category_name:Brass

Code the INSERT statement so MySQL automatically generates the category_id column.

  1. Write an UPDATE statement that modifies the row you just added to the Categories table. This statement should change the product_name column to “Woodwinds”, and it should use the category_id column to identify the row.

  1. Write a DELETE statement that deletes the row you added to the Categories table in exercise 1. This statement should use the category_id column to identify the row.

  1. Write an INSERT statement that adds this row to the Products table:

product_id:

category_id:

product_code:

product_name:

description:

list_price:

discount_percent:

date_added:

The next automatically generated ID

4

dgx_640

Yamaha DGX 640 88-Key Digital Piano

Long description to come.

799.99

0

Today’s date/time.

Use a column list for this statement.

  1. Write an UPDATE statement that modifies the product you added in exercise 4. This statement should change the discount_percent column from 0% to 35%.

  1. Write a DELETE statement that deletes the record with category_id = 4 from the Categories table. When you execute this statement, it will produce an error since the category has related rows in the Products table. To fix that, precede the DELETE statement with another DELETE statement that deletes all products in this category. (Remember that to code two or more statements in a script, you must end each statement with a semicolon.)


error: Content is protected !!