SQL explained: What is SQL | Select Statement | Select Where | Insert | Update/Edit | Delete | Order By | Select Between

SQL Update Statement

Syntax: UPDATE TableName Set ColumnName=Value WhereColumnName2=Value2

If we wanted to update the records from our table 'Members_tbl' in Diagram 1 where the LastName is Jones AND City is equal to Belfast and change the City column value to Belfast we could use the following update SQL statement.

UPDATE Members_tbl Set City='Dublin' Where LastName='Jones' AND City='Belfast'

Diagram 1
Update SQL statement

Diagram 2 shows the results of running our SQL Update.

Diagram 2
Update SQL

If you were to run an SQL Update statement to update all the rows in our table 'Members_tbl' (as it was in Diagram 1) where the City column held the value Belfast then this would have an effect of updating more than one record in our example.
You could also introduce OR as our SQL update statement does below.

UPDATE Members_tbl Set City='Dublin' Where FirstName='Dave' OR City='Belfast'

Get the best asp web hosting provider now and save 30%

Advertisements



MembersPro

MembersPro PayPal - ASP Membership software

Plug and play ASP membership script that integrates with PayPal to let you charge recurring membership fees.