The first solution, the simplest and common method:
Copy codeThe Code is as follows: select top 30 * from article where id not in (select top 45000 id from article order by year desc, id desc) order by year desc, ID DESC
Average query time: 45
SQL Server Stored Procedure paging code and instructions using vc # Call the above Stored Procedure
SQL Server Stored Procedure paging code and instructions using vc # Call the above Stored Procedure
The Code is as follows:
Declare @ TotalCount int
First, this is the definition given by the teacher --
Static task division: the problem is divided into relatively independent sub-problems equal to the number of CPUs;
Dynamic task division: when the problem has n (> Number of CPUs) relatively
This is a good stored procedure. The code is as follows:Copy code /***** Object: StoredProcedure [dbo]. [P_viewPage] script date: 05/14/2012 08:49:34 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCreate PROC [dbo]. [P_viewPage]-- Add the
The first scenario, the simplest, the common method:
Copy Code code as follows:
Select Top * from ARTICLE WHERE ID. (select top 45000 ID to ARTICLE order by year DESC, id DESC) Esc,id DESC
Average Enquiry 100 Time: 45s
The
A stored procedure (stored procedure) is a set of SQL statements designed to accomplish a particular function, compiled and stored in a server-side database, which can be used to accelerate the execution of SQL statements.Custom stored procedures,
Create DATABASE DBTestUse DBTest--Create a test tableCREATE TABLE Pagetest(ID int identity (a) is not NULL,COL01 int NULL,COL02 nvarchar () null,COL03 datetime NULL)--1 Record SetDECLARE @i intSet @i=0while (@iBegin Insert INTO Pagetest Select
SQL Server database paging query has been SQL Server's short board, Idle to do nothing, think of several methods, assuming that there is a table article, Field ID, year ... (other omitted), Data 53,210 (customer real data, amount of small), page 30
The original address: several common SQL paging method efficiency comparisonPaging is important, and interviews are met. You may wish to review and summarize.1. Create a test environment, (inserting 1 million data takes about 5 minutes).Create
In section 2005, we have more options. We can use the new syntax CTE (Public table expression). The paging stored procedures include the following:
1. Use Not in and select top
2. Use the value of id greater than or select top
3. Use the cursor in
SQL Server database paging query has always been a short board of SQL Server, so I have nothing to worry about. I have come up with several methods, for example, table ARTICLE, field ID, YEAR... (others omitted). There are 53210 million pieces of
SQL Paging stored Procedure implementation code
Create PROCEDURE Sp_conn_sort(@tblName varchar (255),--table name
@strGetFields varchar (1000) = ' * ',--columns to be returned
@fldName varchar (255) = ',--sorted field name
@PageSize int =
SQL Server database paging query has been a short board of SQL Server, idle, come up with several methods, assuming that there are table article, Field ID, year ... (other omitted), Data 53,210 (customer real data, quantity is not large), paging
Create PROC p_viewpage_a
/*
Nzperfect [No_miss] Efficient common paging stored procedure (bidirectional retrieval) 2007.5.7 qq:34813284
Warning: Tables or views that apply to a single primary key or existence of a unique value column
Ps:sql
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.