Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
202 Chapter 8: Data Modification If you leave the WHERE clause off an UPDATE, the same modification will be applied to every row in the table. For ex- ample, assume that we add a column for sales tax to the sale table. Someone at the rare book store could use the following statement to compute the tax for every sale: UPDATE sale SET sales_tax = sale_total_amt * 0.075; The expression in the SET clause takes the current value in the sale_total_amt column, multiplies it by the tax rate, and puts it in the sales_tax column. Deleting Rows Like the UPDATE statement, the DELETE statement affects one or more rows in a table based on row selection criteria in a WHERE predicate. The general syntax for DELETE is DELETE FROM table_name WHERE row_selection_predicate For example, if a customer decided to cancel an entire pur- chase, then someone at the rare book store would use some- thing like DELETE FROM sale WHERE customer_numb = 12 AND sale_date = '05- Jul-2013'; Assuming that all purchases on the same date are considered a single sale, the WHERE predicate identifies only one row. Therefore, only one row is deleted. When the criteria in a WHERE predicate identify multiple rows, all those matching rows are removed. If someone at the rare book store wanted to delete all sales for a specific cus- tomer, then the SQL would be written DELETE FROM sale WHERE customer_numb = 6;