0

How to create a transaction with isolation level in SQL.

I'v tried something like this, but obviously it does not work:

INSERT INTO test(col1) VALUES ('test')
SET TRANSACTION ISOLATION LEVEL read stability;
COMMIT WORK;

I'm using SQL DB2 LUW

ahm5
  • 633
  • 5
  • 9

2 Answers2

0

https://www.ibm.com/docs/en/db2/11.5?topic=information-sqlj-set-transaction-clause says:

You can execute SET TRANSACTION only at the beginning of a transaction.

https://www.ibm.com/docs/en/i/7.5?topic=statements-set-transaction says:

The SET TRANSACTION statement can only be executed when it is the first SQL statement in a unit of work, unless:

  • all previous statements executed in the unit of work are SET TRANSACTION statements or statements that are executed under isolation level NC, or

  • it is executed in a trigger.

I'm not a user of DB2, but this seems to say that you must SET TRANSACTION before your INSERT. This matches my experience in other RDBMS products.

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
  • Thank you but that does not work too, it might be that my approach is wrong because I'm getting a syntax error – ahm5 Jun 07 '22 at 18:41
  • `SET TRANSACTION... ;` is one statement. `INSERT ... ;` is a second. `COMIT;` is yet a third. – Charles Jun 07 '22 at 19:10
0

Look at the SET CURRENT ISOLATION statement.

Mark Barinstein
  • 11,456
  • 2
  • 8
  • 16