C C++ Java Data Structure Python JavaScript CSS Ajax PL/SQL PHP Puzzles C programs C++ programs Java programs

Home » SQL

SQL - UPDATE Statement (to update record in table)

SQL - UPDATE Statement: In this article, we are going to learn how to update a record using ‘UPDATE’ statement in SQL.
Submitted by Shubham Singh Rajawat, on November 13, 2017

Update statement is used to update/change any data/record that already exists in a table.

Syntax:

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

Here,

  • table_name : name of the table into which we want to insert data.
  • column1, column2, ... : names of the columns/fields.
  • value1, value2, ... : values of the column/fields specified.
  • condition: it is the condition that defines which data is going to be updated.

We can also update multiple rows/records at a time by the changing the condition in 'WHERE clause'.

sql - update command example

Examples:

1) To update the name of the student whose Enroll_No is 3

UPDATE Student SET Student_name = 'Vaibhav' WHERE Enroll_No = 3;

This will update the name of the student to Vaibhav whose Enrollment number is 3

sql - update command example 1

2) To update city of all the students to Delhi

UPDATE Student SET City = 'Delhi';

This will update the name of the student to Vaibhav whose Enrollment number is 3

sql - update command example 2




Sponsored Links




COMMENTS