Share via


Transações implícitas Transact-SQL

Os aplicativos e scripts DB-Library Transact-SQL usam a instrução Transact-SQL SET IMPLICIT_TRANSACTIONS ON para iniciar o modo de transação implícito. Use a instrução SET IMPLICIT_TRANSACTIONS OFF para desativar o modo de transação implícito. Use as instruções COMMIT TRANSACTION, COMMIT WORK, ROLLBACK TRANSACTION ou ROLLBACK WORK para concluir cada uma das transações.

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