How To Update Values in a Table?
Page 1 of 1
How To Update Values in a Table?
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.
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.
Similar topics
» How To Use Existing Values in UPDATE Statements?
» How To Create a New Table by Selecting Rows from Another Table?
» How To Create a New Table by Selecting Rows from Another Table?
» How To Count Duplicated Values in a Column?
» How To Create a New Table?
» How To Create a New Table by Selecting Rows from Another Table?
» How To Create a New Table by Selecting Rows from Another Table?
» How To Count Duplicated Values in a Column?
» How To Create a New Table?
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Sun Jan 31, 2010 12:35 am by Micheal
» Accessing tables of other users in SQL
Sun Jan 31, 2010 12:34 am by Micheal
» Grouping commands in SQL
Sun Jan 31, 2010 12:32 am by Micheal
» Operations on Result Sets in SQL
Sun Jan 31, 2010 12:31 am by Micheal
» Subqueries in SQL
Sun Jan 31, 2010 12:30 am by Micheal
» Joining Relations in SQL
Sun Jan 31, 2010 12:28 am by Micheal
» Delete comand in SQL
Sun Jan 31, 2010 12:27 am by Micheal
» Update command in SQL
Sun Jan 31, 2010 12:26 am by Micheal
» Insert command in SQL
Sun Jan 31, 2010 12:23 am by Micheal