북스온라인 보면 잘 나오고 어딘가 질문이 있어서 하나 만들어 둡니다.
OUTPUT 절의 활용
if object_id ('Seat') is not null
drop table Seat
go
if object_id ('reservedSeat') is not null
drop table reservedSeat
go
create table Seat
( seatNo int
, seatRow char(1)
, isReserved bit
)
go
set nocount on
begin tran
insert into Seat values (1,'a',0)
insert into Seat values (2,'a',0)
insert into Seat values (3,'a',0)
insert into Seat values (4,'a',0)
insert into Seat values (5,'a',0)
commit tran
go
create table reservedSeat
(reservedNo int
,seatNo int
,seatRow char(1)
)
go
UPDATE SEAT
SET ISRESERVED = 1
OUTPUT INSERTED.SEATNO
, INSERTED.SEATNO
, INSERTED.SEATROW
INTO RESERVEDSEAT
WHERE
SEATNO IN (1,2,3)
AND ISRESERVED <> 1
GO
SELECT @@ROWCOUNT
GO
-- 반드시 적용된 개수를 확인해서 COMMIT 과 ROLLBACK 처리를 해주어야 합니다.
SELECT * FROM RESERVEDSEAT
왕눈봄이(minsouk1) |
[출처] output 의 사용 (sqlmvp) |작성자 왕눈봄이
'SQL Server 2005' 카테고리의 다른 글
Why you want to be restrictive with shrink of database files (0) | 2008.08.22 |
---|---|
Inside Microsoft SQL 2005.TheStorage.chm (0) | 2008.07.23 |
안정적인 데이타베이스 구축과 장애 복구 전략 (0) | 2008.07.16 |
DSN ADD VB Script (0) | 2008.07.15 |
데이터베이스간 제약조건 인덱스 비교검사 (0) | 2008.07.14 |