• subscribe
March 03, 2008 12:00 AM

Jump Start: The UPDATE Statement

SQL Server Pro
InstantDoc ID #98439

To change the value of a column in a particular row of a table, you can use the T-SQL UPDATE statement. The syntax is straightforward: The UPDATE command is followed immediately by the table name, then by the SET keyword, which specifies which column or columns will be updated. If the SET keyword specifies multiple columns, you separate the column names with commas.

Like the DELETE statement, which I described in "Using the DELETE Statement," InstantDoc ID 98388 (http://www.sqlmag.com/Articles/ArticleID/98388/98388.html), the T-SQL UPDATE statement is set-oriented, so you need to use it very carefully. For example, the statement

UPDATE MyTable SET ColumnData = 'All Values'
would change the value of the ColumnData column to All Values for every row in the table named MyTable. But you'd probably never want to change the value of a column for every row of a table--unqualified UPDATEs are typically used only for mass-maintenance operations.

Consequently, your code should almost always indicate specifically which rows you want to update. Applications typically use the WHERE clause to identify the row or rows that will be updated. For instance, you'd use the code

UPDATE MyTable SET ColumnData = 'One Value', ColumnDate = GETDATE()
WHERE ColumnID = 1
to modify the values in the ColumnData and ColumnDate columns for the row whose ColumnID column is equal to 1.


ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here
  • SP1?
    I know there is a SP1 for SQL 2008 R2 available....and there is a "feature pack" as well... ...
  • SQL database mirroring
    I have SQL Server 2008 R2 Enterprise 64bit on Windows 2008 R2 Enterprise 64bit.  Each SQL Server has...
  • Dell Compellent Disk Drive
    Does anybody has experience with Dell Compellent Disk Drive? Basically, this system manages all disk...
  • Sql server performance tuning
    I need to find a tool that help me to optimize sql server,queries,improve the performance and solve ...