SQL Query to Update All Columns in a Table
Last Updated :
14 Nov, 2021
In SQL, sometimes we need to write a single query to update the values of all columns in a table. We will use the UPDATE keyword to achieve this. For this, we use a specific kind of query shown in the below demonstration. For this article, we will be using the Microsoft SQL Server as our database and Select keyword.
Step 1: Create a Database. For this use the below command to create a database named GeeksForGeeks.
Query:
CREATE DATABASE GeeksForGeeks
Output:

Step 2: Use the GeeksForGeeks database. For this use the below command.
Query:
USE GeeksForGeeks
Output:

Step 3: Create a table of SALARY inside the database GeeksForGeeks. This table has 2 columns namely MONTHLY_SALARY and ANNUAL_SALARY containing the monthly and annual salaries of the workers in a factory.
Query:
CREATE TABLE SALARY(
MONTHLY_SALARY INT,
ANNUAL_SALARY INT);
Output:

Step 4: Describe the structure of the table SALARY.
Query:
EXEC SP_COLUMNS SALARY;
Output:

Step 5: Insert 5 rows into the SALARY table.
Query:
INSERT INTO SALARY VALUES(10000,120000);
INSERT INTO SALARY VALUES(20000,240000);
INSERT INTO SALARY VALUES(15000,180000);
INSERT INTO SALARY VALUES(30000,360000);
INSERT INTO SALARY VALUES(25000,300000);
Output:

Step 6: Display all the rows of the SALARY table.
Query:
SELECT * FROM SALARY;
Output:

Step 7: Update all the columns of the table SALARY. Increase the value of all entries of the MONTHLY_SALARY column by 1000, accordingly, increase the value of all entries of the ANNUAL_SALARY column by 12*1000=12000.
Syntax:
UPDATE TABLE_NAME SET COLUMN1=VALUE1,
COLUMN2 = VALUE2;
Query:
UPDATE SALARY SET MONTHLY_SALARY =
MONTHLY_SALARY+1000,ANNUAL_SALARY=
ANNUAL_SALARY+12000;
Output:

Step 8: Display all the rows of the updated SALARY table.
Query:
SELECT * FROM SALARY;
Output:
Similar Reads
SQL Query to Update All Rows in a Table Updating all rows in a SQL table is a common task when we need to make changes to every record without specifying individual rows. This operation can be performed using the UPDATE statement combined with the SET clause, which allows for modifying values across all rows of a specified table. Understa
5 min read
How to Update a Column in a Table in SQL Server In the database management area, updating columns in a table is a normal query and it is important software that ensures the accuracy and integrity of data. Whether we are making spelling corrections, editing or altering existing information, or being attentive to changing requirements, carrying out
4 min read
SQL Query to Update Columns Values With Column of Another Table The SQL UPDATE statement is one of the most powerful tools for modifying data in a relational database. Sometimes, we need to update column values in one table based on values from another table. This can be done using various methods such as JOIN or nested SELECT statements. In this article, we wil
4 min read
How to Update All Rows in SQL? Updating records in an SQL database is a fundamental operation used to modify existing data. The UPDATE command is the go-to method for making such modifications, whether for all rows in a table or a subset based on specific conditions. In this article, we will explain how to update all rows in SQL
4 min read
How to Update Records in Table from CTE in SQL Common Table Expressions (CTEs) in SQL is an important feature that provides a temporary result set that can be referred to within a SELECT, INSERT, UPDATE, or DELETE statement. In this article, we will learn how to use CTEs to update records in SQL along with examples along with an explanation.What
4 min read