


Redgate activation server code#
The following piece of T-SQL code creates the stored procedure p_ins_products in the AdventureWorks database. Right, we have to create a stored procedure that performs an INSERT statement to the Production.Product table of the AdventureWorks database. The first step to debug a Trigger is to create a stored procedure that encapsulates the statement that is able to fire the Trigger that you want to debug.
Redgate activation server how to#
Now we have to debug this Trigger and below you will learn how to do it. The customer in which we deployed that Trigger complains that some products have the safety threshold lower than 10.
Redgate activation server series#
Debugging a Trigger is possible with Microsoft Visual Studio development tool (except Express edition).Ĭonsider the first version of the Trigger Production.TR_Product_StockLevel in the my previous blog post of this series SQL Server Triggers Tips & Tricks: Working on multiple rows: USE GO CREATE TRIGGER Production.TR_Product_StockLevel ON Production.Product AFTER INSERT AS BEGIN /* Avoid to insert products with safety stock level lower than 10 */ BEGIN TRY DECLARE SMALLINT SELECT = SafetyStockLevel FROM inserted IF 0) ROLLBACK THROW - Re-Throw END CATCH END Īs you probably have already seen, the first version of that Trigger doesn’t work properly with multiple rows because it hadn’t been thought to work on multiple rows. Suppose that this Trigger works into a problem probably, this question comes to your mind: “Can I debug a Trigger” and if it is possible, “How can I do it?”. Now, think about a Trigger that performs a very complex operation silently.

Debugger usually has a graphic interface that allows you to inspect the variables values at run-time to analyze source code and program flow row-by-row and finally to manage breakpoints.Įach developer loves debugging tools because they are very useful when a program fails in a calculation or when it returns an error. The modern and most important Programming Languages have debugging tools integrated into the development tool. Part 2: Triggers must be thought to work on multiple rows.The first and the second part can be found here: This is the third blog post in the series of articles dedicated to the SQL Server Triggers development. SQL Server Tips & Tricks: How to debug a Trigger
