UPDATE Table

UPDATE

Sometimes one needs to change some or all the values in a particular row that is already existing. This can be done using the UPDATE command. It specifies the rows to be changed using the WHERE clause, and the new data using the SET keyword. The new data can be a specified constant, an expression or data from other tables.

” If you do not use WHERE clause all the records will be updated! “

SYNTAX:

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

EXAMPLE

Table before updating
UPDATE students
SET Section="C"
WHERE Section ="";
Table after updating

You can also update multiple column. To update multiple columns, multiple column assignments can be specified with SET keyword separated by commas. All of the assignments will still be made to the table, a single row at a time.

update students
SET Section ="C", Subject ="Maths"
WHERE Name = "Shawn";
After update
update students
SET Roll = NULL
Where Roll = 1;

One thought on “UPDATE Table

Add yours

Leave a comment

Create a website or blog at WordPress.com

Up ↑

Design a site like this with WordPress.com
Get started