codingstreets
Search
Close this search box.

Get Started: SQL UPDATE Statement

In This Article You Will Know About SQL UPDATE Statement. 

SQL UPDATE Statement – Before moving ahead, let’s know a bit about SQL Null Values.

Table of Contents

UPDATE Statement

The UPDATE statement is used to modify or change the existing value in the table.

UPDATE Syntax

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

Note: It is essential to mention the WHERE statement while modifying records; if we forget the WHERE statement, all records will be changed in the table.

Example Database

Below is the example of a database table named “details.”

Id

Name

Class

section_id

1

Alex

5

1

2

Rolex

6

2

3

Salex

7

2

4

Lelex

8

3

5

Kelex

9

5

UPDATE Statement Example

Example: Use ‘UPDATE’ statement to modify the value in ‘Class’ column.

				
					UPDATE details
SET Class = 2
WHERE Name = 'Alex';
				
			

As a result, it returns updated value of ‘Class’ column where name is ‘Alex’.

Example: Use ‘UPDATE’ statement to modify the value in ‘Class’ and section_id column.

				
					UPDATE details
SET Class = 2, section_id = 4
WHERE Name = 'Rolex';
				
			

As a result, it returns updated value of ‘Class’ and section_id column where name is ‘Rolex’.

UPDATE Multiple Records

Example: Use ‘UPDATE’ statement to modify the value in ‘Class’ column.

				
					UPDATE details
SET section_id = 7
WHERE section_id = 2;
				
			

As a result, it returns updated value of all records of ‘section_id’ column where section_id = 2.

UPDATE All Values

				
					UPDATE details
SET Class = 3;
				
			

As a result, it returns updated value for each record in “Class” column.

If you find anything incorrect in the above-discussed topic and have further questions, please comment below.

Connect on:

Recent Post

Popular Post

Top Articles

Archives
Categories

Share on