ERROR_NUMBER()
: returns the number of the errorERROR_SEVERITY()
: returns the error severity (11-19)ERROR_STATE()
: returns the state of the errorERROR_LINE()
: returns the number of the line of the errorERROR_PROCEDURE()
: returns the name of stored procedure/trigger. NULL if there is not stored procedure/triggerERROR_MESSAGE()
: returns the error messagesIF NOT EXISTS ( Query )
RAISERROR('message', ~ );
recommended by Microsoft over RAISERROR
ref: https://parksuseong.blogspot.com/2018/10/mssql-raiseerror-vs-throw.html
more details ) ref: https://sqlhints.com/tag/raiserror-vs-throw/
SELECT * FROM sys.messages
Transfer $100 from account A to B
Operation 2 FAILS -> Can't subtract $100 from acc A
START TRANSACTION
COMMIT
ROLLBACK
Number of BEGIN TRAN statements that are active in the current connection.
RETURNS greater than 0 : open transaction
RETURNS 0 : no open transaction
savepoints
:
SAVE TRAN savepoint 1;
XACT_ABORT
: specifies whether the current trasaction will be automatically rolled back when an error occurs.Concurrency: two or more transactions that read/change shared data at the same time
isolate our transaction from other transactions
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITED
: read rows modified by other transactions without been committed/rolled back