T-SQL/MySQL: Update only one record
March 25th, 2009 by Elchie
If you want to update just the first record and it’s not possible to work with specialized conditions within the where clause in MySQL you can do this:
update table set field=1 limit 0,1
But limit won’t work with T-SQL - what to do? Idea: Use top. Normally top used within select-statements:
select top 5 from table
But using this in an update results in a syntax-error:
update top 1 table set field=1
You have to change the top-syntax to top(n) and it works:
update top(1) table set field=1
Posted in SQL