I'm using my web app to query a relatively huge table, and I only want to return N number of rows from the table.
I've reviewed the MSDN material, but I can't find any references to whether
firstly retrieves every record from the database, or if it functions similarly to SQL Server's
If, I'm concerned
will it operate as intended and only retrieve the N number of records directly, or will it pull all data and get the top N number of records?
It makes the best effort it can.
Given that you appear to be using SQL Server, whose engine is aware of SQL Server's existence,
It'll employ that. Additionally, MS Access would make use of this.
It would utilize PostgreSQL, MySQL, or SQL Lite if you were using
The potential usage of
"fetch first " + n + " rows only"
regular DB2 and SQL 2008 format) or
"select first " + n + "from"
"select * from (" + restOfQuery + ") where rownum <= " + n
on Oracle or whichever particular database was required.
And if someone created a database engine that could not under any circumstances support such limits, it might in fact close the result stream once it had taken what it required.
In each instance, it makes the best effort possible given the circumstances.
In addition, it applies the same methodology to a value of
with its variations and a value of
including its variations (since you need to try to take at least 2 rows to test that there is only 1 to take).