This is the last of my three posts on triggers. We’ve already covered INSERT and UPDATE TRIGGERS. This time we’re doing DELETE triggers. All the same rules apply to DELETE triggers that apply to INSERT and UPDATE triggers. CREATE TRIGGER t_tablename_delete ON TableName AFTER|FOR|INSTEAD OF DELETE AS T-SQL code Just like for the INSERT TRIGGER,…
Month: July 2008
Sub Queries With Multiple Levels of Nesting
Let’s go back to sub queries for a bit. You can nest a sub query within a sub query. There really is no limit. But in doing so, you really need to make sure there isn’t a better way, like a join, or Common Table Expression. The following query finds the names of employees who…
Sub Query Fundamentals
Here we are with another sub query post. A sub query is a query that is nested inside a SELECT, INSERT, UPDATE, or DELETE statement, or inside another sub query. A sub query can be used anywhere an expression is allowed. Here’s an example of a sub query in the SELECT clause of a SQL…
The Error Message
When dealing with errors, it’s often necessary to log, or pass on errors to your users. In either case, you’ve already seen how to trap the ERROR_NUMBER. This time I’ll show you how to get the ERROR_MESSAGE. The ERROR_MESSAGE function takes no argument and it returns a string. BEGIN TRY DECLARE @Number TINYINT, @Result TINYINT;…