blog post

The UPDATE statement updates data values in a database.
UPDATE can update one or more records in a table.
Use the WHERE clause to UPDATE only specific records.

The SQL UPDATE syntax

The general syntax is:
UPDATE table-name 
   SET column-name = value, column-name = value, ...

To limit the number of records to UPDATE append a WHERE clause:
UPDATE table-name 
   SET column-name = value, column-name = value, ...
 WHERE condition

SQL UPDATE Examples

Problem: discontinue all products in the database
UPDATE Product
   SET IsDiscontinued = 1

Note: the value 1 denotes true.
Problem: Discontinue products over $50.
UPDATE Product
   SET IsDiscontinued = 1
 WHERE UnitPrice > 50

Note: the value 1 denotes true.
Problem: Discontinue product with Id = 46.
UPDATE Product
   SET IsDiscontinued = 1
 WHERE Id = 46

This is a more common scenario in which a single record is updated.
Note: the value 1 denotes true.
Problem: Supplier Norske Meierier (Id = 15) has moved: update their city, phone and fax.
UPDATE Supplier
   SET City = 'Oslo', Phone = '(0)1-953530', Fax = '(0)1-953555'
 WHERE Id = 15

This is a common scenario in which a single record is updated.

  • Share This Story


Pleas give your valuable comments to improve the contents.

about author

Atul kumar shukla


I'm Atul Kumar Shukla, working as a web developer.
Welcome to my Blog. This is my personal blog where i post my own questions and answers , articles about ASP.Net., SQL Server, HTML, CSS, Jquery and many more..

Visit Profile

Leave a comment

Name
E-mail
Url
Message

Get More Stuff
Subscribing to the TheOneblogs newsletter and get intersting stuff and updates to your email inbox.
Your Email

 

Style Switcher

Change Color

×! We use cookies to improve your user experience. More information