Sponser Link

SQL Server update rows in table

In existing data, you need for UPDATE the existing data. You can update single of multiple rows using UPDATE statement and WHERE clause for required data. Syntax is given below.

  UPDATE table1
  SET column2 = 'Your Text', column3 = 45000
  WHERE column1=5

Here table1 can be any table and you will set the column value as per column type. For example in nvarchar or varchar, value will be in ‘’ and for integer or decimal without single quotation.

Here is example for update the data

Firstly we will create the table.

 CREATE TABLE SalesTransaction (
	Trx_id int PRIMARY KEY IDENTITY (1, 1),
	Item_Number nvarchar(50),
	Unit_Price decimal(18,4),
	Quantity int,
	Total_Amount decimal(18,4),
	Cust_Id int,
	UpdateOn datetime

To update existing data you need trx_id for filter or you can write expression as per your requirement.

  Update salesTransaction
  Set Unit_Price=45.41,Item_Number='Milk-1'
  Where trx_id=1249

You may like : UPDATE JOIN