SQL – UPDATE Statement

The UPDATE Query in SQL is used to modify and change the existing values in the columns. The WHERE clause is used with the UPDATE Statement which has a condition to update the selected columns. The WHERE clause determines which records will be updated.

  • Syntax of UPDATE statement –

UPDATE table_name
SET column1 = value1, column1 = value1 ,..., columnN = valueN
WHERE condition;

The SQL UPDATE query cannot be rolled back. When we execute the query, it will change all the values as per the condition in the WHERE clause. It is asked to be careful while doing so.

Demo Table –

Product Table

Category Region City Country Customer_ID Customer_name
Office Supplies Central Chicago United States SM-20950 Suzanne McNair
Technology East New York City United States AH-10465 Amy Hunt
Office Supplies East New York City United States AH-10465 Amy Hunt
Office Supplies East Dover United States EP-13915 Emily Phan
Office Supplies East Dover United States EP-13915 Emily Phan
Technology West Aurora United States TP-21565 Tracy Poddar
Office Supplies West Aurora United States TP-21565 Tracy Poddar
Office Supplies East Long Beach United States AR-10825 Anthony Rawles
Office Supplies West Pasadena United States HA-14920 Helen Andreada
Furniture West Pasadena United States HA-14920 Helen Andreada

 

Example – Consider the Product table of the Customer database, and update the Country name from the United States to the U.S where the category is Office supplies.

UPDATE [dbo].[Products]
SET
[Country/Region] = 'U.S' WHERE Category = 'Office Supplies';

 

This output is the small section of the output by executing the above query –

Category Region City Country Customer_ID Customer_name
Office Supplies Central Chicago U.S SM-20950 Suzanne McNair
Technology East New York City United States AH-10465 Amy Hunt
Office Supplies East New York City U.S AH-10465 Amy Hunt
Office Supplies East Dover U.S EP-13915 Emily Phan
Office Supplies East Dover U.S EP-13915 Emily Phan
Technology West Aurora United States TP-21565 Tracy Poddar
Office Supplies West Aurora U.S TP-21565 Tracy Poddar
Office Supplies East Long Beach U.S AR-10825 Anthony Rawles
Office Supplies West Pasadena U.S HA-14920 Helen Andreada
Furniture West Pasadena United States HA-14920 Helen Andreada

In the output, the Country name is changed to the U.S from the United States wherever we have the category as Office supplies.

 

Follow us on TwitterFacebookLinkedin, and Tableau Public to stay updated with our latest blog and what’s new in Tableau.

Automate data analysis pipeline and create report ready dashboards

If you are looking forward to getting your data pipeline built and setting up the dashboard for business intelligence, book a call now from here.

#analytics #data #business #artificialintelligence #machinelearning #startup #deeplearning #deeplearning #datascience #ai #growth #dataanalytics #india #datascientist #powerbi #dataanalysis #tableau #SQL #businessanalytics #businessanalyst #businessandmanagement #dataanalyst #businessanalysis #analyst #analysis #powerbideveloper #powerbidesktop #letsviz

Established in 2020, Lets Viz Technologies provides a full range of high-quality data analysis and data visualization services. We are also an authorized Zoho Partner.

 

Contact

WeWork Berger Delhi One, C-001/A2, Sector 16B, Noida, Uttar Pradesh 201301

0124-502-5592
info@lets-viz.com

We are Social

Trust Pilot Reviews