SET Rowcount - TSQL Tutorial

SET Rowcount - sets the number of rows for sql query.
When the specified number of rows are returned the execution of query stops.

SET Rowcount Syntax:

SET ROWCOUNT { number | @number_variable } ;

SET Rowcount Example:

USE model;
GO
SET ROWCOUNT 3;
GO
SELECT * FROM Departments WHERE id <=3;
GO

IDName
1Anthropology
2Biology
3Chemistry

USE model;
GO
SET ROWCOUNT 2;
GO
SELECT * FROM Departments;
GO

IDName
1Anthropology
2Biology