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 VIDEOS
 
 
SQL E/BOOKS   WORLD, USA & SQL NEWS   FORMAT
SCRIPTS SQL 2005 SQL 2008 ARTICLES
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
SQL 2016 DESIGN & PROGRAMMING
 
 
 
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