sql - How to check when a transaction occurs -
Is anyone ever asked to know when the transaction occurs?
BEGIN TRAN BEGIN --- Choose the accessories with @INTST @ TBT (ID, Colo_1, COMO_2) @id, @ val1, valbo, ..... ..... ...... END IF (@@ error 0) Start Role Tran before the end of the Quoted Tran - & gt; Want to know when it started or was logged? - "XE some_trans_log getDate (), 'start-web_sp @id' are about to be added here here EXEC web_sp_id-> It takes a while to execute - exe some_trans_log getDate () about adding I'm thinking, 'end-web_sp @id' END
I do not think it is necessary to enter your transaction, but I can make a mistake.
This is your way, the first is the @@ error
function as soon as an error occurs. And if any other statement has been executed after an error has occurred, then @@ error is set to zero.
To properly use the @@ error function, its variable is stored in its variable You will have to do as soon as you execute the statement but to estimate where an error can occur and to store the value of its variable, beat more than one way.
In the server I have used catch blocks which makes such execution very easy.
If you try to block your main code and if any error is raised during code execution, control jumps to hold the block, then you will have to gather detailed information about the error .
I will use the following approach to write a code like this ....
BEGIN try / * Check here for some explicit verification / / / 1 check (some do not really exist) BEGIN RAISEROR ('Something went wrong', 16,1) END - - Check (if something is not true) BEGIN RAISERROR ('Something went wrong', 16,1) END / * Once you complete your check, open a transaction / TBBI (ID, call, call) 2) SELECT @id, @ val_1, val_2, end in the cumulated transaction / * If the verification failed and an error was raised control this catch block The transaction will jump in the transaction. If all the verification was passed and the transaction was open, then something went wrong. Then this will roll back the open transaction * / IF @@ TRANCOUNT & lt; & Gt; 0 RALLB Use the error function to collect information about a transaction interval [ERROR_NUMBER] / * error [ERROR_MESSAGE] as ERROR_LINE (), [ERROR_MESSAGE] as ERROR_MESSAGE, ERROR_NUMBER * / / * Other logs information about error blah blah * / END catch
Comments
Post a Comment