SQL Update

Use Sql Update to change values in a table.

You can do it on a single-row, group of rows or all rows. The new data can be a constant value or an expression using certain function.

The syntax to update data in a table:

UPDATE table_name
SET column_name=expression,column_name=expression, . . .
WHERE conditions

If there is a WHERE condition in the Update statement, it is a good idea to test the condition first. To do that , apply the Where condition into the Sql Select statement. Verify that the result from that Sql select is the rows that you want to update. That way you can feel confident that you are changing the correct rows.

Let's use our previous table as an example. We are supposed to change the value of column B in table Tbl_L for ID number 2. Currently the value is 50 and we want to change it into 55.

This is the statement:

SET B = 55

Let's use this simple example to show how to verify the WHERE conditions. To do this, change the UPDATE into SELECT * FROM and remove the SET statement. Leave the WHERE conditions.

Now, this is what we got:

SET B = 55>   <--remove this statement

Run the Sql statement, and verify that the result is what you expected. If it is then run the Update statement.

The syntax to update data in a table with the value from other table:

UPDATE table2
SET    table2.price = table1.price
FROM   table2
       INNER JOIN table1
         ON ( table2.rowid = table1.rowid ); 
Buy at AllPosters.com
A bend in the road is not the end of the road... unless you fail to make the turn

Positive Resources

All of us have at least two or three things that excite us. We could talk about these subjects for hours. Good news!. Did you know that Site Built It! can turn this type of deep interest and enthusiasm into a revenue-generating business?

Review some of the Site Build It! case studies and you'll absolutely discover something that ignites more positive ideas into your mind.

SBI! Video Tour

Invest the most
important 30 minutes
you will spend online.

Click, sit back, and
understand why SBI!
makes you succeed.