Oracle equivalent ROWNUM for SQL-Server 2005?

2019-04-11 02:40发布

问题:

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?

回答1:

SELECT TOP 100 * FROM TABLE

You can also filter rows by using where class

SELECT TOP 100 * FROM YOURTABLE WHERE YOURCONDITION


回答2:

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

SELECT TOP 100 * FROM MY_TABLE


回答3:

select top 100 * from tbl

column name is required or use *



回答4:

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.



回答5:

SELECT TOP 100 * FROM MY_TABLE

Sorry if I misunderstood.

Edit: Must be faster