SQL tutorial | Interview questions | Oracle
Would you like to react to this message? Create an account in a few clicks or log in to continue.

How To Update Values in a Table?

Go down

How To Update Values in a Table? Empty How To Update Values in a Table?

Post by Micheal Sat Jan 16, 2010 9:35 pm

If you want to update some values in one row or multiple rows in a table, you can use the
UPDATE statement. The script below shows a good example:
UPDATE fyi_links SET counts = 999, notes = 'Good site.'
WHERE id = 101;
1 row updated.
SELECT * FROM fyi_links WHERE id = 101;
ID URL NOTES COUNTS CREATED
----- ------------------------ ------------ ------- ---------
101 http://dev.fyicenter.com Good site. 999 07-MAY-06
How To Update Values on Multiple Rows?
If the WHERE clause in an UPDATE matches multiple rows, the SET clause will be applied to all
matched rows. This rule allows you to update values on multiple rows in a single UPDATE
statement. Here is a good example:
UPDATE fyi_links SET counts = 9, notes = 'Wrong URL'
WHERE id >= 250;
3 rows updated.
SELECT * FROM fyi_links WHERE id >= 250;
ID URL NOTES COUNTS CREATED
----- ------------------------ ------------ ------- ---------
250 Retail Sales.com Wrong URL 9 07-MAY-06
260 Recruiting.com Wrong URL 9 07-MAY-06
270 Payroll.com Wrong URL 9 07-MAY-06
This statement updated 3 rows with the same new values on all 3 rows.

Micheal
Admin

Posts : 243
Join date : 2010-01-10

http://sql-tutorial.co.cc

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum