Bookmark and Share

Tuesday, October 30, 2007

HOWTO update or delete on SQL server a limited number of rows, like TOP condition

If you need to update a limited number of rows on a sql table using a "top"  like condition, here is a solution:

SET ROWCOUNT 100

-- update
SET ROWCOUNT 100
update table1 set column1 = getdate()
-- only 100 rows will be updated
-- delete
SET ROWCOUNT 10
delete from table1
-- only 10 rows will be deleted