Reputation: 4747
I have a SQL Server 2014 database called Database.Main
which has columns Type
and Code
.
I need to modify an existing Transact-SQL script to select all the rows that have Type
equal to MyObject.Main
and change the Code
to integer 1000.
How can I do this in Transact-SQL?
BEGIN TRY
BEGIN TRAN Update_Table;
COMMIT;
END TRY
BEGIN CATCH
print 'Error encountered updating entries'
print ERROR_MESSAGE()
rollback;
END CATCH
Answer
Based on the answer from Raul below the solution is this:
BEGIN TRY
BEGIN TRAN Update_Table;
UPDATE Database.Main
SET Code = 1000
WHERE Type = 'MyObject.Main';
COMMIT;
END TRY
BEGIN CATCH
print 'Error encountered updating entries'
print ERROR_MESSAGE()
rollback;
END CATCH
Upvotes: 1
Views: 75
Reputation: 77866
A simple UPDATE
command would do?
update table_name
set Code = 1000
where Type = 'MyObject.Main';
Upvotes: 5