SQL Commands

Modifying Records

To modify one or more existing record, you use the UPDATE statement. To use this command, you state the table to update, the values you want fields to be changed to, and, what records to be changed. For example,

UPDATE Users SET UserName = 'James Smith', Password = 'NEWPASSWORD' WHERE UserID = 10

In this case, all records which had a UserID of 10 would have their UserName and Password fields changed to the values given. If you only want one record to be updated, you need to ensure that in the WHERE clause, you specify a condition that will only return one record. This would normally be a unique id/primary key field.

Note that you do not have to include all the fields for the record.

If you want to update more than one record, you simply change the condition specified in the WHERE clause. For example,

UPDATE Furniture SET Price = 10 WHERE ItemType = 'Cupboard'

would change the Price field to 10 for all records in the Furniture table where their ItemType field had was "Cupboard".

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Owning a computer without programming is like having a kitchen and using only the microwave oven” - Charles Petzold