SQL UPDATE Statement (2024)

Last Updated : 10 Jun, 2024

Summarize

Comments

Improve

SQL UPDATE Statement modifies the existing data from the table.

UPDATE Statement in SQL

The UPDATE statement in SQL is used to update the data of an existing table in the database. We can update single columns as well as multiple columns using the UPDATE statement as per our requirement.

In a very simple way, we can say that SQL commands(UPDATE and DELETE) are used to change the data that is already in the database. The SQL DELETE command uses a WHERE clause.

Update Syntax

The syntax for SQL UPDATE Statement is :

UPDATE table_name SET column1 = value1, column2 = value2,…
WHERE condition;

Where,

  • table_name: name of the table
  • column1: name of first, second, third column….
  • value1: new value for first, second, third column….
  • condition: condition to select the rows for which the

Parameter Explanation

  1. UPDATE: Command is used to update the column value in the table.
  2. WHERE: Specifies the condition which we want to implement on the table.

Note: In the above query the SET statement is used to set new values to the particular column and the WHERE clause is used to select the rows for which the columns are needed to be updated. If we have not used the WHERE clause then the columns in all the rows will be updated. So the WHERE clause is used to choose the particular rows.

SQL UPDATE Statement Examples

Let’s see the SQL update statement with examples.

First we will create a table, on which we will use the UPDATE Statement. To create the table, write the following query:

Query:

SQL
CREATE TABLE Customer( CustomerID INT PRIMARY KEY, CustomerName VARCHAR(50), LastName VARCHAR(50), Country VARCHAR(50), Age int(2), Phone int(10));-- Insert some sample data into the Customers tableINSERT INTO Customer (CustomerID, CustomerName, LastName, Country, Age, Phone)VALUES (1, 'Shubham', 'Thakur', 'India','23','xxxxxxxxxx'), (2, 'Aman ', 'Chopra', 'Australia','21','xxxxxxxxxx'), (3, 'Naveen', 'Tulasi', 'Sri lanka','24','xxxxxxxxxx'), (4, 'Aditya', 'Arpan', 'Austria','21','xxxxxxxxxx'), (5, 'Nishant. Salchichas S.A.', 'Jain', 'Spain','22','xxxxxxxxxx');   Select * from Customer;

The created table will look like this:

SQL UPDATE Statement (1)

Update Single ColumnUsing UPDATE Statement Example

Update the column NAME and set the value to ‘Nitin’ in the rows where the Age is 22.

Query:

UPDATE Customer SET CustomerName 
= 'Nitin' WHERE Age = 22;

Output:

SQL UPDATE Statement (2)

Updating Multiple Columns using UPDATE Statement Example

Update the columns NAME to ‘Satyam’ and Country to ‘USA’ where CustomerID is 1.

Query:

UPDATE Customer SET CustomerName = 'Satyam', 
Country = 'USA' WHERE CustomerID = 1;

Output:

SQL UPDATE Statement (3)

Note: For updating multiple columns we have used comma(,) to separate the names and values of two columns.

Omitting WHERE Clause in UPDATE Statement

If we omit the WHERE clause from the update query then all of the rows will get updated.

Query:

UPDATE Customer SET CustomerName = 'Shubham';

Output:

The table Customer will now look like this,

SQL UPDATE Statement (4)

Important Points About SQL UPDATE Statement

  • SQL UPDATE Statement is used to update data in an existing table in the database.
  • The UPDATE statement can update single or multiple columns using the SET clause.
  • The WHERE clause is used to specify the condition for selecting the rows to be updated.
  • Omitting the WHERE clause in an UPDATE statement will result in updating all rows in the table.


H

Harsh Agarwal

SQL UPDATE Statement (5)

Improve

Please Login to comment...

SQL UPDATE Statement (2024)
Top Articles
Electricity costs in Kenya
QR Clip and Scan - Chrome Web Store
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Pearson Correlation Coefficient
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Nfsd Web Portal
Selly Medaline
Latest Posts
Article information

Author: Laurine Ryan

Last Updated:

Views: 6143

Rating: 4.7 / 5 (77 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Laurine Ryan

Birthday: 1994-12-23

Address: Suite 751 871 Lissette Throughway, West Kittie, NH 41603

Phone: +2366831109631

Job: Sales Producer

Hobby: Creative writing, Motor sports, Do it yourself, Skateboarding, Coffee roasting, Calligraphy, Stand-up comedy

Introduction: My name is Laurine Ryan, I am a adorable, fair, graceful, spotless, gorgeous, homely, cooperative person who loves writing and wants to share my knowledge and understanding with you.