Sie sind auf Seite 1von 3

Transaction Semantics: ANSI vs.

BTET Mode The matrix on the facing page displays differences in transaction semantics between ANSI and BTET modes. In particular, you see how rollback of a terminated session is handled. Note: When using BEGIN and END transaction (BTET) to delineate a transaction, the outcome status should be checked after each statement. Otherwise, if an SQL statement fails the transaction will be terminated. All SQL updates to that point will be automatically rolled back. However, any following SQL statements will be executed using implicit transaction mode and the ET will generate a warning because the transaction actually ended on the failed statement Data Manipulation 11-21 Transaction Semantics:ANSI vs. BTET Mode ANSI mode BTET mode (explicit) BTET mode (implicit) UPD A UPD B COMMIT /* both commit */ BT UPD A UPD B ET /* both commit */ UPD A /* A commits */ UPD B /* B commits */ UPD A UPD B /* fails */ COMMIT /* A commits */ BT UPD A UPD B /* fails */ /* then both rollback */ UPD A /* A commits */ UPD B /* fails */ UPD A UPD B ROLLBACK /* both rollback */ BT UPD A UPD B ROLLBACK /* both rollback */ ROLLBACK is not applicable in implicit transactions. UPD A UPD B

LOGOFF /* both rollback */ BT UPD A UPD B LOGOFF /* both rollback */ UPD A /* A commits */ UPD B /* B commits */ LOGOFF 11-22 Data Manipulation DDL and Transactions A DDL statement must be the last statement in a transaction. ANSI Compliant When in ANSI session mode, ANSI session semantics are in effect. A DDL statement either implicitly begins a transaction, or occurs within an exis ting transaction. Several results may occur, depending on how the transaction is term inated: After the DDL statement: Commit or roll back DDL*? If the DDL is followed by a COMMIT WORK statement Commit If the DDL is followed by a ROLLBACK WORK statement Roll back If the session submitting the SQL is terminated before either a COMMIT or ROLLBACK WORK statement is submitted Roll back *Entire transaction is actually affected. Teradata Extensions When in BTET session mode, Teradata session semantics are in effect. In BTET session mode, a transaction may be implicit or explicit: After the DDL statement: Commit or roll back DDL*? Implicit Commit Explicit If the DDL is followed by an ET; (end transaction) statement Commit If the DDL is not followed by an ET; (ex., if you accidentally place any statement following the DDL) Roll back If any failure or error occurs before the ET; is executed Roll back *Entire transaction is actually affected. Differences: ANSI vs. Teradata SQL Topic ANSI Teradata SQL DDL in a transaction Requires COMMIT WORK following DDL Requires ET following DDL if explicit transaction. Must be last statement in a macro. Data Manipulation 11-23 DDL and Transactions DDL must be the last statement in a transaction. DDL must be the only statement in a macro. .SET SESSION TRANSACTION ANSI .SET SESSION TRANSACTION ANSI DDL must be followed by COMMIT WORK or ROLLBACK WORK Example: CREATE TABLE test_1 (f1 INTEGER); COMMIT WORK; In implicit transaction, DDL is a single-statement transaction

Example: CREATE TABLE test_1 (f1 INTEGER); In explicit transaction, DDL must be followed by ET (End Transaction) Example: BT; CREATE TABLE test_1 (f1 INTEGER); ET; 11-24 Data Manipulation Notes Macros 12-1 Module 12 Macros After completing this module, you will see how to: Create and use a macro. Modify and drop a macro. Create a parameterized macros. Use macros to provide secure access to data.

Das könnte Ihnen auch gefallen