2009년 8월 28일 금요일

동적으로 원하는 개수만큼 행을 다루기(TOP, ROWCOUNT)

SELECT TOP 20 * FROM HumanResources.Employee


DECLARE @top
INT
SET
@top =
10
SELECT TOP(@top) * FROM HumanResources.Employee

-- set value
DECLARE @top
INT
SET
@top =
10
SET
ROWCOUNT @top
SELECT * FROM
HumanResources.Employee
-- set value to return all rows
SET ROWCOUNT
0

-- update example
DECLARE @top
INT
SET
@top =
10
UPDATE TOP(@top) HumanResources.Employee SET MaritalStatus = 'S' WHERE EmployeeID <
20


-- delete example
DECLARE @top
INT
SET
@top =
10
DELETE TOP(10) HumanResources.Employee WHERE EmployeeID <
20


-- insert example
DECLARE @top
INT
SET
@top =
10
INSERT TOP(@top)
dbo.contact2
SELECT * FROM dbo.contact

댓글 없음:

댓글 쓰기