SQL UPDATE

SQL UPDATE Statement

This staement of update by Sql

Sql update where

Syntax: UPDATE Table Set fied1= Value1 , field2= Value2, … WHERE Emplid =’Test’;

UPDATE table_name
SET column1 = value1, column2 = value2, …
WHERE condition;

For Example:

Update Table Set Name=’Dakdee’ Where Emplid =’TT005′;

Update Table Set Name=’Dakdee’, LastName=’Toodd’ Where Emplid =’TT005′;

Sql update from select

Update TableName a  set(a.column1, a.column2,a…) = (select column1, column2,… from tablename b where b.key = a.key) where exists (select ‘X’ from tablename b where b.key = a.key)

Sql update with join

Example 1

UPDATE tablename1
INNER JOIN tablename2 ON tablename1.value = tablename2.DESCR
SET tablename1.value = tablename2.IDKEY
WHERE tablename1.IDCODE=’XX’;

Example 2

UPDATE Person
SET
Person.PersonCityName=Address.City,
Person.PersonPostCode=Addrrss.PostCode
FROM Persons Person
INNER JOIN
Address Addrress
ON Person.Id = Addrrss.Id

If you want update muticolumn by sql then read more update select sql example.

Posted in SQL.