- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the use of update command in SQL?
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|CSE priya|ECE hari|EEE sneha|CSE priya|ECE hari|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|40 priya|assistant director|45 hari|developer|46 ram|projectmanager|42 priya|assistant director|47 hari|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|50000 priya|assistant director|45|45000 hari |developer |46|30000 ram |projectmanager |42|55000 priya|assistant director|47|50000 hari |developer |48|35000
- Related Articles
- Difference Between ALTER and UPDATE Command in SQL
- How to use update command in Android sqlite?
- What is the use of IGNORE_SPACE SQL mode?
- What is the use of ALLOW_INVALID_DATES SQL mode?
- What is the SQL command to return the field names of a table?
- What is the use of Get-Process command in PowerShell?
- What is the use of NO_UNSIGNED_SUBTRACT SQL mode in handling overflow?
- What is the difference between the New-AZTag and Update-AZTag command in Azure PowerShell?
- Show MySQL host via SQL Command?
- Explain the use of delete command in DBMS
- How to execute UPDATE SQL in a JSP?
- What is the equivalent of SQL “like” in MongoDB?
- How to execute SQL update query in a JSP?
- How to know if MySQL binary log is enabled through SQL command?
- What is the purpose of the command interpreter?

Advertisements