MSSQL - ROW_NUMBER

DB 2011.11.01 17:29
Create table Employee ( EmployeeID INT , EmployeeName Varchar(30))
ROWNUM using ROW_NUMBER
SELECT ROW_NUMBER () OVER (ORDER BY EmployeeID) AS RowNumber, EmployeeName
FROM Employee ORDER BY EmployeeID

ROWNUM using IDENTITY
SELECT IDENTITY(int, 100, 1) AS RowNumber , EmployeeName
INTO #tmp
FROM Employee ORDER BY EmployeeID
SELET RowNumber , EmployeeID FROM #tmp

ROWNUM using NEWID
SELECT NEWID() ,AS RowNumber, EmployeeName FROM Employee
ORDER BY EmployeeID

Related article:
http://samsudeenb.blogspot.com/2009/06/how-to-generate-sequence-number-in-sql.html



맨날헷갈려....
신고

'DB' 카테고리의 다른 글

[펌]Mysql설계시 고려사항  (1) 2014.11.20
MYSQL 테이블 복사  (0) 2014.09.13
테이블복사  (1) 2011.11.23
MSSQL - ROW_NUMBER  (0) 2011.11.01
ERROR : Conversion failed when converting date and/or time from character string.  (0) 2011.04.19
1 ... 17 18 19 20 21 22 23 24 25 ... 77


티스토리 툴바