codesnout.com

SQL UPDATE

Google Ads

SQL UPDATE


SQL Sample Code - SQL UPDATE.


UPDATE table_name
SET column1=value, column2=value2, column3=value3...
WHERE specified_column=specified_value;

Always include the WHERE clause otherwise all columns will be updated

See the examples section below for an explanation.


What does the SQL UPDATE statement do?

The SQL UPDATE statement simply updates the value of a record in a table.


Sample – SQL UPDATE

In this SQL sample we will use the database table ‘tblCompany’.

Company_ID CompanyName Address Town Sales
1 SQL Sample 1 Sample St Hamburg 10000
2 SQL Code Land 2 Code Rd Hamburg 20000
3 Sample Code World 66 SQL St Curry 18000
4 SQL Reference Ltd 34 Reference St Pisa 17000

In the table above we want to update the SQL Reference Ltd record as they have moved Address from number 34 to 50 Reference St and their Sales figures have also changed.

Use the SELECT statement below:

UPDATE tblCompany SET Address=’50 Reference St ' AND Sales=‘21000’ WHERE Address=’34 Reference St’ AND Sales=’17000’;

The table of results will look like this:

Company_ID CompanyName Address Town Sales
1 SQL Sample 1 Sample St Hamburg 10000
2 SQL Code Land 2 Code Rd Hamburg 20000
3 Sample Code World 66 SQL St Curry 18000
4 SQL Reference Ltd 50 Reference St Pisa 21000

 


Related SQL Sample Code:


About Us | Privacy Policy | Contact Us | ©2010 Thunderousity Information Management Solutions | www.autosnout.com - Car Performance Statistics Website Utilising SQL | SQL Blog |

SQL Home | SQL Intro | SQL SELECT Statement | DISTINCT | WHERE | SQL Wildcards | AND OR | IN | BETWEEN | LIKE | ORDER BY | GROUP BY | TOP | ALIAS | DELETE | INSERT | UPDATE | CREATE DATABASE | CREATE TABLE | ALTER | INNER JOIN | FULL JOIN | LEFT JOIN | RIGHT JOIN | UNION | CONSTRAINTS | NOT NULL| Aggregate Functions | SUM | AVG | COUNT | MAX | MIN | FIRST | LAST | GROUP BY | HAVING | LIMIT | Microsoft Access Data Types | MySQL Data Types | SQL Server Data Types | ASCII HTML Reference Sheet |