Transact-SQL 암시적 트랜잭션
DB-Library 응용 프로그램과 Transact-SQL 스크립트는 Transact-SQL SET IMPLICIT_TRANSACTIONS ON 문을 사용하여 암시적 트랜잭션 모드를 시작합니다. 암시적 트랜잭션 모드를 해제하려면 SET IMPLICIT_TRANSACTIONS OFF 문을 사용합니다. 각 트랜잭션을 종료하려면 COMMIT TRANSACTION, COMMIT WORK, ROLLBACK TRANSACTION 또는 ROLLBACK WORK 문을 사용합니다.
SET QUOTED_IDENTIFIER OFF;
GO
SET NOCOUNT OFF;
GO
USE AdventureWorks;
GO
CREATE TABLE ImplicitTran
(Cola int PRIMARY KEY,
Colb char(3) NOT NULL);
GO
SET IMPLICIT_TRANSACTIONS ON;
GO
-- First implicit transaction started by an INSERT statement.
INSERT INTO ImplicitTran VALUES (1, 'aaa');
GO
INSERT INTO ImplicitTran VALUES (2, 'bbb');
GO
-- Commit first transaction.
COMMIT TRANSACTION;
GO
-- Second implicit transaction started by a SELECT statement.
SELECT COUNT(*) FROM ImplicitTran;
GO
INSERT INTO ImplicitTran VALUES (3, 'ccc');
GO
SELECT * FROM ImplicitTran;
GO
-- Commit second transaction.
COMMIT TRANSACTION;
GO
SET IMPLICIT_TRANSACTIONS OFF;
GO