DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
SITE SEARCH SQLUSA.com HEADLINES NEWS
SQL E/BOOKS   SQL 2014 PROGRAMMING   DOWNLOADS
SCRIPTS SQL 2005 SQL 2008 ARTICLES
SQL JOBS TWITTER FORMAT VIDEOS
How to limit updates on a table?

The following SQL Sever T-SQL samples demonstrates the usage of SET ROWCOUNT and TOP to put a cap on updates:

-- T-SQL limiting the number of UPDATEs

USE tempdb;

SELECT EmployeeId = CONVERT(INT,EmployeeID), ManagerID

INTO Employee

FROM AdventureWorks.HumanResources.Employee

GO

-- (290 row(s) affected)

 

UPDATE TOP (5) Employee

SET ManagerID = 109

GO

-- (5 row(s) affected)

 

SET ROWCOUNT 7

UPDATE Employee

SET ManagerID = 100

SET ROWCOUNT 0

GO

-- (7 row(s) affected)

 

DROP TABLE Employee

Related article:

How to use the MERGE statement instead of UPDATE?

 

Exam Prep 70-461
Exam 70-461
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE