Advertisement
PavloSerg

Лаба транзакции

May 3rd, 2023
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. USE eda7kDB
  2. go
  3. create or alter proc PrintTrans as
  4. begin
  5. select transaction_id, name, transaction_begin_time
  6. ,case transaction_type
  7. when 1 then '1 = Read/write transaction'
  8. when 2 then '2 = Read-only transaction'
  9. when 3 then '3 = System transaction'
  10. when 4 then '4 = Distributed transaction'
  11. end as transaction_type
  12. ,case transaction_state
  13. when 0 then '0 = The transaction has not been completely initialized yet'
  14. when 1 then '1 = The transaction has been initialized but has not started'
  15. when 2 then '2 = The transaction is active'
  16. when 3 then '3 = The transaction has ended. This is used for read-only transactions'
  17. when 4 then '4 = The commit process has been initiated on the distributed transaction'
  18. when 5 then '5 = The transaction is in a prepared state and waiting resolution'
  19. when 6 then '6 = The transaction has been committed'
  20. when 7 then '7 = The transaction is being rolled back'
  21. when 8 then '8 = The transaction has been rolled back'
  22. end as transaction_state
  23. ,case dtc_state
  24. when 1 then '1 = ACTIVE'
  25. when 2 then '2 = PREPARED'
  26. when 3 then '3 = COMMITTED'
  27. when 4 then '4 = ABORTED'
  28. when 5 then '5 = RECOVERED'
  29. end as dtc_state
  30. ,transaction_status, transaction_status2,dtc_status, dtc_isolation_level, filestream_transaction_id
  31. from sys.dm_tran_active_transactions
  32. end
  33. go
  34.  
  35. exec PrintTrans
  36. select @@TRANCOUNT
  37.  
  38. begin tran laba
  39. select @@TRANCOUNT
  40.  
  41. select *
  42. from SeregaTheDed_SQLLogin_1.rel_orders_products
  43.  
  44. save tran t1--rollback_delete_tran
  45. select @@TRANCOUNT
  46. delete
  47. from SeregaTheDed_SQLLogin_1.rel_orders_products
  48. where count > -1
  49.  
  50. select *
  51. from SeregaTheDed_SQLLogin_1.rel_orders_products
  52. rollback tran t1--rollback_delete_tran
  53. select @@TRANCOUNT
  54.  
  55. select *
  56. from SeregaTheDed_SQLLogin_1.rel_orders_products
  57.  
  58. begin tran commit_delete_tran
  59. select @@TRANCOUNT
  60. delete
  61. from SeregaTheDed_SQLLogin_1.rel_orders_products
  62. where count > -1
  63.  
  64. select *
  65. from SeregaTheDed_SQLLogin_1.rel_orders_products
  66.  
  67. commit tran commit_delete_tran
  68. select @@TRANCOUNT
  69.  
  70. select *
  71. from SeregaTheDed_SQLLogin_1.rel_orders_products
  72.  
  73.  
  74.  
  75. rollback tran laba
  76. select @@TRANCOUNT
  77.  
  78. select *
  79. from SeregaTheDed_SQLLogin_1.rel_orders_products
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement