SQL UPDATE Statement


The SQL UPDATE statement is used to update or modify the existing records in a specific table.

The SQL UPDATE statement is also used to update all records (without SQL WHERE clause) or specific records that match a specified criteria using SQL WHERE clause. This is accomplished by carefully constructing a where clause.


Search Keys

  • sql update query
  • sql update
  • update query in sql
  • sql update value
  • update column sql
  • update statement in sql
  • update command in sql
  • mysql update where
  • t sql update
  • sql update example
  • sql update syntax
  • sql update multiple
  • update from table
  • update table query
  • mssql update set
  • sql update field
  • sql multiple update
  • update sql date
  • update table set column
  • update record in sql
  • update multiple columns oracle
  • sql update set multiple values
  • sql update column value
  • update sql command
  • sql update where in

SQL UPDATE Syntax

The basic syntax of SQL UPDATE statement with SQL WHERE clause is as follows:


UPDATE table_name1
SET column_name1 = value_1, column_name2 = value_2,...column_nameN = value_N
WHERE some_column_name_1 = some_value_1;

You can combine N number of conditions using AND or OR operators.

Note: The SQL WHERE clause in the SQL UPDATE statement!

The SQL WHERE clause specifies criteria to update, which row or rows that should be updated. If you omit the SQL WHERE clause, all rows will be updated!


Sample Database Table - Books

BookId BookName BookPrice RelYear DomainName AuthorName
1 Head First SQL 123.45 2012 Performance Geetha
2 From Access To SQL Server 178.69 2009 Optimization Vinoth Kumar
3 Oracle PL/sql By Example 150 2009 Performance Devi Mai
4 Postgre Sql Server Programming 60 2008 Performance Devi Mai
5 The Complete Guide to SQL 100 2013 Security Siva Kumar
6 Microsoft SQL Server 2012 99.99 2006 Optimization Rishi Keshan

Sample Database Table Structure - Books

Column Name Data Type
BookID Number
BookName Text
BookPrice Number
RelYear Number
DomainName Text
AuthorName Text

Text Column Vs Numeric Column

SQL requires single or double (most database support) quotes around text or string values. However, we write numeric fields without quotes:


SQL UPDATE Example

Example 1

The following SQL statement will update a existing row, but only update data in the "AuthorName" and "BookPrice" column for BookID = 2, in the "Books" table:


UPDATE Books
SET AuthorName = 'Devi Mai', BookPrice = 260
WHERE BookID = 2;

The result of above query is:

BookId BookName BookPrice RelYear DomainName AuthorName
1 Head First SQL 123.45 2012 Performance Geetha
2 From Access To SQL Server 260 2009 Optimization Devi Mai
3 Oracle PL/sql By Example 150 2009 Performance Devi Mai
4 Postgre Sql Server Programming 60 2008 Performance Devi Mai
5 The Complete Guide to SQL 100 2013 Security Siva Kumar
6 Microsoft SQL Server 2012 99.99 2006 Optimization Rishi Keshan

Example 2

The following SQL statement will update two existing rows, but only update data in the "BookPrice", "RelYear" and "DomainName" columns for AuthorName = "Devi Mai" and BookID greater than "2", in the "Books" table:


UPDATE Books
SET BookPrice = 180, RelYear = 2010, DomainName = 'Programming'
WHERE AuthorName = 'Devi Mai' AND BookID > 2;

The result of above query is:

BookId BookName BookPrice RelYear DomainName AuthorName
1 Head First SQL 123.45 2012 Performance Geetha
2 From Access To SQL Server 260 2009 Optimization Devi Mai
3 Oracle PL/sql By Example 180 2010 Programming Devi Mai
4 Postgre Sql Server Programming 180 2010 Programming Devi Mai
5 The Complete Guide to SQL 100 2013 Security Siva Kumar
6 Microsoft SQL Server 2012 99.99 2006 Optimization Rishi Keshan

Example 3

The following SQL statement will update all existing rows, but only update data in the "BookPrice", "RelYear" and "DomainName" column, in the "Books" table:


UPDATE Books SET 
BookPrice = 50, RelYear = 2016, DomainName = 'Sql Programming';

The result of above query is:

BookId BookName BookPrice RelYear DomainName AuthorName
1 Head First SQL 50 2016 Sql Programming Geetha
2 From Access To SQL Server 50 2016 Sql Programming Devi Mai
3 Oracle PL/sql By Example 50 2016 Sql Programming Devi Mai
4 Postgre Sql Server Programming 50 2016 Sql Programming Devi Mai
5 The Complete Guide to SQL 50 2016 Sql Programming Siva Kumar
6 Microsoft SQL Server 2012 50 2016 Sql Programming Rishi Keshan

Search Keys

  • sql update statement example
  • sql query update
  • update record sql
  • update database sql
  • sql command to update
  • sql update multiple set
  • sql update table from table
  • sql update format
  • script update sql
  • update set where in
  • sql query to update multiple rows
  • update where select sql
  • update query with select
  • multiple updates in one query sql
  • postgres update statement
  • update from mssql
  • sql update multiple fields
  • update column value sql
  • sql update all columns
  • sql multiple updates in one query
  • sql change value in table
  • sql change data
  • sql query to change value
  • sql modify
  • set command in sql