中文网站
  Advanced Search
Read the latest Blogs from IT professionals in the field. Read and write community created documents. Need IT help? Ask our staff. Connect with your peers. Check our Tech Shop for posters, books and software tools. Home

4.8.3 Database Systems: Updates

1. Updating allows us to change some values in a tuple without necessarily changing all.

2. Some examples:
(a) To increase all balances by 5 percent.

update account
set balance=balance * 1.05

This statement is applied to every tuple in account.

(b) To make two di erent rates of interest payment, depending on balance amount:

update account
set balance=balance * 1.06
where balance > 10,000

update account
set balance=balance * 1.05
where balance ≤ 10,000
Note: in this example the order of the two operations is important. (Why?)

3. In general, where clause of update statement may contain any construct legal in a where clause of a select statement (including nesting).

4. A nested select within an update may reference the relation that is being updated. As before, all tuples in the relation are first tested to see whether they should be updated, and the updates are carried out afterwards.

For example, to pay 5% interest on account whose balance is greater than average, we have

update account
set balance=balance * 1.05
where balance > select avg (balance) from account

Database System Structure: