Transactions implicites Transact-SQL

Les applications de bibliothèque DB-Library et les scripts Transact-SQL utilisent l'instruction Transact-SQL SET IMPLICIT_TRANSACTIONS ON pour activer le mode de transaction implicite. Utilisez l'instruction SET IMPLICIT_TRANSACTIONS OFF pour désactiver le mode de transaction implicite. Utilisez les instructions COMMIT TRANSACTION, COMMIT WORK, ROLLBACK TRANSACTION ou ROLLBACK WORK pour terminer chaque transaction.

SET QUOTED_IDENTIFIER OFF;
GO
SET NOCOUNT OFF;
GO
USE AdventureWorks2008R2;
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