Sometimes, using n in topn is a variable, you need to use () to complete: declare @ count1intset @ count18selecttopstrong (@ count1) strong * fromMyTable can achieve the same effect if setRowCount is used. declare @ count1intset @ count18setRowCount @ count1s
Sometimes, if n in top n is a variable, you need to use (): declare @ count1 intset @ count1 = 8 select top strong (@ count1) /strong * from MyTable can achieve the same effect if set RowCount is used. declare @ count1 intset @ count1 = 8 set RowCount @ count1s
Sometimes, if n in top n is a variable, you need to use:
declare @count1 intset @count1 = 8select top (@count1) * from MyTable
If set RowCount is used, the same effect can be achieved.
declare @count1 intset @count1 = 8 set RowCount @count1select * from MyTable
Note that using set RowCount has a side effect. Once set, the subsequent statements will be affected, and SQL Server will change this in subsequent versions, so be careful when using it.
Important: |
In the next version of SQL Server, using SET ROWCOUNT does not affect the DELETE, INSERT, and UPDATE statements. In the new development work, avoid using the set rowcount statement with the DELETE, INSERT, and UPDATE statements, and plan to modify the application currently using the statement. In addition, for the DELETE, INSERT, and UPDATE statements currently using set rowcount, we recommend that you use TOP syntax to overwrite them. For more information, see DELETE (Transact-SQL), INSERT (Transact-SQL), or UPDATE (Transact-SQL ). |