Updating Existing Data

The UPDATE statement is used to update existing data in a database. For example, if you want to change the company name in the Suppliers table you can run an UPDATE statement to edit it. Listing 4.4 shows the basic structure of an UPDATE statement.

Listing 4.4. The Basic Structure of an UPDATE Statement
UPDATE
        {
         table_name WITH ( < table_hint_limited > [ ...n ] )
         | view_name
         | rowset_function_limited
        }
        SET
        {  column_name = {  expression | DEFAULT | NULL }
        | @variable = expression
        | @variable = column = expression }  [ ,...n ]

    {  {  [ FROM {  < table_source > }  [ ,...n ] ]
        [ WHERE
            < search_condition > ] }
        |
        [ WHERE CURRENT OF
        {  {  [ GLOBAL ] cursor_name }  | cursor_variable_name }
        ] }
        [ OPTION ( < query_hint > [ ,...n ] ) ] 

Get Programming Data-Driven Web Applications with ASP.NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.