Uncategorized

ROWCOUNT

Setting the SET ROWCOUNT option causes most Transact-SQL statements to stop processing when they have been affected by the specified number of rows. This includes triggers.

SET ROWCOUNT 5

SELECT
	ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) N
FROM ( VALUES(0),(0),(0),(0),(0),(0),(0),(0),(0),(0) ) a (n)
GO
-- (5 rows affected)

SET ROWCOUNT overrides the SELECT statement TOP keyword if the rowcount is the smaller value.

SET ROWCOUNT 5

SELECT TOP(3)
	ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) N
FROM ( VALUES(0),(0),(0),(0),(0),(0),(0),(0),(0),(0) ) a (n)
GO
-- (5 rows affected)

SET ROWCOUNT 5

SELECT TOP(8)
	ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) N
FROM ( VALUES(0),(0),(0),(0),(0),(0),(0),(0),(0),(0) ) a (n)
-- (5 rows affected)