UPDATE with TOP (SQL Server)
UPDATE with TOP (SQL Server) is a SQL statement in the DML Statements category. SQL Server: limits the UPDATE to N rows. Useful for batch processing without locking huge numbers of rows. The syntax is UPDATE TOP (n) table SET column = value WHERE condition;. It returns limited update. A typical example: UPDATE TOP (1000) employees SET bonus = salary * 0.1 WHERE department = 'IT'; -- Only updates first 1000 matching rows -- Chunking pattern for large updates: WHILE @@ROWCOUNT > 0 BEGIN UPDATE TOP (1000) employees SET status = 'processed' WHERE status = 'pending'; END -- Processes rows in 1000-row batches -- Prevents long-running locks and log bloat A close relative is INSERT INTO, which inserts new rows into a table. A close relative is UPDATE, which modifies existing rows in a table. Always use WHERE to avoid updating all rows. A close relative is DELETE, which removes rows from a table. Always use WHERE to avoid deleting all rows.