Loved by learners at thousands of companies
It is critical to know how to handle errors and manage transactions when programming SQL scripts. Unhandled errors can be very harmful and can cause unexpected situations, such as inconsistent data in your database, or even worse, errors can lead you to make wrong business decisions. In this course, you will learn how to handle errors and discover how to manage transactions in case of an error. Additionally, you will study what happens when two or more people interact at the same time with the same data. You will practice all these concepts using two datasets, one of them based on bank accounts and the other one on an electric bike store.
Starting with error handlingFree
To begin the course, you will learn how to handle errors using the TRY...CATCH construct that provides T-SQL. You will study the anatomy of errors, and you will learn how to use some functions that can give you information about errors.Welcome!50 xpThe TRY...CATCH syntax50 xpYour first error-handling script100 xpNesting TRY...CATCH constructs100 xpError anatomy and uncatchable errors50 xpAnatomy review50 xpCorrecting compilation errors100 xpGiving information about errors50 xpError function syntax50 xpUsing error functions100 xpUsing error functions in a nested TRY...CATCH100 xp
Raising, throwing and customizing your errors
In this chapter, you will deepen your knowledge of handling errors. You will learn how to raise errors using RAISERROR and THROW. Additionally, you will discover how to customize errors.RAISERROR50 xpRAISERROR syntax50 xpCATCHING the RAISERROR100 xpTHROW50 xpTHROW with or without parameters50 xpTHROW without parameters100 xpExecuting a stored procedure that throws an error100 xpTHROW with parameters100 xpCustomizing error messages in the THROW statement50 xpWays of customizing error messages50 xpConcatenating the message100 xpFORMATMESSAGE with message string100 xpFORMATMESSAGE with message number100 xp
Transactions in SQL Server
In this chapter, you will be introduced to the concept of transactions. You will discover how to commit and rollback them. You will finish by learning how to return the number of transactions and their state.Transactions50 xpTransaction statements50 xpCorrecting a transaction100 xpRolling back a transaction if there is an error100 xpChoosing when to commit or rollback a transaction100 xp@@TRANCOUNT and savepoints50 xpModifiers of the @@TRANCOUNT value50 xpChecking @@TRANCOUNT in a TRY...CATCH construct100 xpUsing savepoints100 xpXACT_ABORT & XACT_STATE50 xpXACT_ABORT behavior50 xpXACT_ABORT and THROW100 xpDoomed transactions100 xp
Controlling the concurrency: Transaction isolation levels
This chapter defines what concurrency is and how it can affect transactions. You will learn exciting concepts like dirty reads, repeatable reads, and phantom reads. To avoid or allow this reads, you will explore, one by one, the different transaction isolation levels.Transaction isolation levels50 xpConcurrency phenomena50 xpUsing the READ UNCOMMITTED isolation level100 xpREAD COMMITTED & REPEATABLE READ50 xpChoosing the correct isolation level50 xpPrevent dirty reads100 xpPreventing non-repeatable reads100 xpSERIALIZABLE isolation level50 xpPrevent phantom reads in a table100 xpPrevent phantom reads just in some rows100 xpSNAPSHOT50 xpSetting READ COMMITTED SNAPSHOT to ON50 xpComparing WITH (NOLOCK) & READ UNCOMMITTED50 xpAvoid being blocked100 xpCongratulations!50 xp
PrerequisitesIntermediate SQL Server
Miriam is a freelance Software Engineer with 15+ years of experience. She is focused on analyzing, designing, and developing software applications. She also collaborates with the UOC University supervising Bachelor theses. Miriam loves programming and experimenting with different technologies. She is passionate about databases and enjoys playing with data. She holds a Master of Science Degree in Computer Engineering.