Team Fly 

Page 47

  3  where  cust_id = 28983;

   CUST_ID CUST_CREDIT_LIMIT
---------- -----------------
     28983               15000

SQL> update customers
  2  set    cust_credit_limit = 20000
  3  where  cust_id = 28983;

1 row updated.

SQL> select cust_id, cust_credit_limit
  2  from   customers
  3  where  cust_id = 28983;
 
   CUST_ID CUST_CREDIT_LIMIT
---------- -----------------
     28983             20000

This example reveals that customer 28983 had a $15,000 credit limit before the update statement was executed. The update statement is written against the CUSTOMERS table with a set clause issued against the column to be changed, cust_credit_limit, and a where clause to make the change only for customer 28983. After the command is executed, a select statement reveals that the customer now has a credit limit of $20,000. The update statement is a very powerful tool. It can be used against one record, multiple records meeting simple or complex criteria, or all records in a table.

Ask the Expert

Q: Can you use a where clause with every type of DML statement?

A: The where clause can be used only with select, update, and delete statements. The insert statement can never have a where clause.

Q: You mentioned that a where clause is optional for update statements. What would happen if one isn't used during an update?

A: If a where clause isn't used with an update statement, every record in the table will be updated.

Team Fly 
0066