SQL Server MSDN : https://technet.microsoft.com/ko-kr/library/gg699618(v=sql.110).aspx


웹 관련 프로그래머라면...

페이징 처리에 상당한 고민을 하게된다...


데이터가 작다면 상관이 없겠지만... 데이터가 1만건은 기본이고, 100만건 1000만건 정도일 경우...

view화면을 보는 이용자 입장에서는 10건에서 최대 50건 정도를 확인하는데...

100만건을 조회하고 싶지는 않을 것 이다


또한, 시스템도 그 만큼 부하를 받을 것 이다.


my-sql 이나 오라클 같은 경우 limit 과 같은 페이징을 쉽게 할 수 있는 명령 문을 제공한다.

하지만, MSSQL은 지금 것 페이징이라는 것을 제공하지 않았다... 하지만...


하지만...

 

올래~ 홧팅2


2012버전 부터 페이징 관련 명령을 제공한다.


[ORDER BY { order_by_expression [ ASC | DESC ] } [ ,...n][<offset_fetch>] ] 
<offset_fetch> ::= {OFFSET { integer_constant | offset_row_count_expression } { ROW | ROWS }    [FETCH { FIRST | NEXT } {integer_constant | fetch_row_count_expression } { ROW | ROWS } ONLY]}


예 )

다음 예에서는 ORDER BY와 함께 OFFSET-FETCH 절을 사용하는 방법을 보여 줍니다.

예제 1 정렬된 결과 집합에서 첫 10개 행을 건너뛰고 나머지 행을 반환합니다.

SELECT First Name + ' ' + Last Name FROM Employees ORDER BY First Name OFFSET 10 ROWS;

예제 2- 정렬된 결과 집합에서 첫 10개 행을 건너뛰고 다음 5개 행을 반환합니다.

SELECT First Name + ' ' + Last Name FROM Employees ORDER BY First Name OFFSET 10 ROWS FETCH NEXT 5 ROWS ONLY;


* 자세한 내용은 위에 링크되어 있는 MSDN을 참조 하자!



NameAliasesDescription
bigintint8signed eight-byte integer
bigserialserial8autoincrementing eight-byte integer
bit [ (n) ] fixed-length bit string
bit varying [ (n) ]varbitvariable-length bit string
booleanboollogical Boolean (true/false)
box rectangular box on a plane
bytea binary data ("byte array")
character varying [ (n) ]varchar [ (n) ]variable-length character string
character [ (n) ]char [ (n) ]fixed-length character string
cidr IPv4 or IPv6 network address
circle circle on a plane
date calendar date (year, month, day)
double precisionfloat8double precision floating-point number (8 bytes)
inet IPv4 or IPv6 host address
integerintint4signed four-byte integer
interval [ fields ] [ (p) ] time span
line infinite line on a plane
lseg line segment on a plane
macaddr MAC (Media Access Control) address
money currency amount
numeric [ (ps) ]decimal [ (ps) ]exact numeric of selectable precision
path geometric path on a plane
point geometric point on a plane
polygon closed geometric path on a plane
realfloat4single precision floating-point number (4 bytes)
smallintint2signed two-byte integer
serialserial4autoincrementing four-byte integer
text variable-length character string
time [ (p) ] [ without time zone ] time of day (no time zone)
time [ (p) ] with time zonetimetztime of day, including time zone
timestamp [ (p) ] [ without time zone ] date and time (no time zone)
timestamp [ (p) ] with time zonetimestamptzdate and time, including time zone
tsquery text search query
tsvector text search document
txid_snapshot user-level transaction ID snapshot
uuid universally unique identifier
xml XML data

+ Recent posts