What is the use of update command in SQL? (2024)

Update command is a data manipulation command which is used to edit the records of a table. It may be used to update a single row based on a condition, all rows or set of rows based on the condition given by the user.

It is used along with the SET clause, operationally, a WHERE clause may be used to match conditions −

Example 1

An example is given below for the use of update command −

update table student set name=’sneha’ where branch=’CSE’;

Example 2

Given below is another example of the usage of update command −

create table employee(ename varchar(30),department varchar(20));insert into employee values('pinky','CSE');insert into employee values('priya','ECE');insert into employee values('hari','EEE');select * from employee;update employee set ename='sneha' where department='CSE';select * from employee;

Output

You will get the following output −

pinky|CSEpriya|ECEhari|EEEsneha|CSEpriya|ECEhari|EEE

Update the value of a column

Given below is an example to update table employee set age=age+1:

create table employee(ename varchar(30),department varchar(20), age number(30));insert into employee values('ram','projectmanager',40);insert into employee values('priya','assistant director',45);insert into employee values('hari','developer',46);select * from employee;update employee set age=age+2;select * from employee;

Output

You will get the following output −

ram|projectmanager|40priya|assistant director|45hari|developer|46ram|projectmanager|42priya|assistant director|47hari|developer|48

Update multiple columns in one statement

Given below is an example to update table salary set −

Here,

  • bonus=bonus+5000
  • basic=basic+(0.2*bonus)

Example

create table employee(ename varchar(30),department varchar(20), age number(30), salary number(20));insert into employee values('ram','projectmanager',40,50000);insert into employee values('priya','assistant director',45,45000);insert into employee values('hari','developer',46,30000);select * from employee;update employee set age=age+2, salary= salary+5000;select * from employee;

Output

You will get the following output −

ram |projectmanager |40|50000priya|assistant director|45|45000hari |developer |46|30000ram |projectmanager |42|55000priya|assistant director|47|50000hari |developer |48|35000

Updated on: 03-Jul-2021

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started

What is the use of update command in SQL? (31)

Advertisem*nts

';adpushup.triggerAd(ad_id); });

What is the use of update command in SQL? (2024)
Top Articles
Latest Posts
Article information

Author: Foster Heidenreich CPA

Last Updated:

Views: 5590

Rating: 4.6 / 5 (76 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Foster Heidenreich CPA

Birthday: 1995-01-14

Address: 55021 Usha Garden, North Larisa, DE 19209

Phone: +6812240846623

Job: Corporate Healthcare Strategist

Hobby: Singing, Listening to music, Rafting, LARPing, Gardening, Quilting, Rappelling

Introduction: My name is Foster Heidenreich CPA, I am a delightful, quaint, glorious, quaint, faithful, enchanting, fine person who loves writing and wants to share my knowledge and understanding with you.