SQL Server obtains row n data

Source: Internet
Author: User
In sql2005, you can use row_number to obtain row n data in a table without a primary key, but you must specify the sorting column, otherwise, you have to use select into to transition to a temporary table and add a sorting field.
Use the fetch absolute statement of the cursor to obtain the data of a row under the absolute number of rows. The test code is as follows:
Set nocount on -- create a test environment and insert data, and the table does not have the primary key create table test (ID int, name varchar (10) insert into test select 999, 'jinjazz' insert into test select 888, 'csdn 'insert into test select 999, 'sqlserver' -- Obtain the absolute number of rows through the cursor declare mycursor scroll cursor for select * From testopen mycursorfetch absolute 3 from mycursor close mycursordeallocate mycursor -- delete test environment drop table testset nocount off/* -- ID ----------- ---------- 999 sqlserver --*/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.