Share via


Transazioni implicite in Transact-SQL

Nelle applicazioni DB-Library e negli script Transact-SQL la modalità di transazione implicita viene attivata tramite l'istruzione Transact-SQL SET IMPLICIT_TRANSACTIONS ON e disattivata tramite l'istruzione SET IMPLICIT_TRANSACTIONS OFF. Per terminare le singole transazioni, è possibile utilizzare le istruzioni COMMIT TRANSACTION, COMMIT WORK, ROLLBACK TRANSACTION o 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

Vedere anche

Altre risorse

SET IMPLICIT_TRANSACTIONS (Transact-SQL)
BEGIN TRANSACTION (Transact-SQL)
COMMIT TRANSACTION (Transact-SQL)
ROLLBACK TRANSACTION (Transact-SQL)
ROLLBACK WORK (Transact-SQL)
COMMIT WORK (Transact-SQL)

Guida in linea e informazioni

Assistenza su SQL Server 2005