SQL Basic- SQL UPDATE Command



SQL UPDATE



This statement is used to update records in a table.



SQL UPDATE Statement 


The SQL update statement is used to update existing record in a table.

Syntax:


[To update the existing record into the table, we are using SQL UPDATE command as follows:]


UPDATE table_name 

SET col1=value1, col2=value2 

WHERE column=value;






Note:

WHERE clause:

In SQL UPDATE Statement, WHERE clause specifies which record should be updated.

If you don't use WHERE clause,then SQL UPDATE condition update all records.


Data Is Updated Only in Specified Columns:

The following statement will update existing record as per the specifies condition in WHERE Clause.



Below is existing  "Student" table:






Example 1:

[we update existing student "Ajeet" with a new Address in "Student" table.]

The following statement are used as to Update a existing "Ajeet's " record into the "Student" table:


UPDATE Student

SET Address='Delhi'

WHERE StudentName='Ajeet';


Result:


Message Comes: (1 row(s) affected)