简体   繁体   中英

Oracle equivalent ROWNUM for SQL-Server 2005?

In Oracle PL/SQL I was used to write:

SELECT * FROM MY_TABLE WHERE ROWNUM <= 100;

in order to fetch only the first 100 records of the table named MY_TABLE.

What could be the equivalent SELECT statement in SQL SERVER?

In SQL-Server You can Use TOP to select the no. of rows.

SELECT TOP 100 * FROM MY_TABLE
select top 100 * from tbl

列名是必需的或使用*

SELECT TOP 100 * FROM MY_TABLE

Sorry if I misunderstood.

Edit: Must be faster

SELECT TOP 100 * FROM TABLE

您还可以使用where class过滤行

SELECT TOP 100 * FROM YOURTABLE WHERE YOURCONDITION

In SQL Server 2012, you can use OFFSET and FETCH to determine which rows to return. They're documented under ORDER BY ; This makes sense since asking for 100 rows, when tables are by definition unordered, gives unpredictable results.

Similarly, if you use other's answers, re: TOP , you should also have an ORDER BY clause, or else it's not defined which rows will be returned.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM