OK, so we’re all familiar with triggers now, right? You have seen that using a trigger you can log a change to a table in a special log file, or we can create a related record in another table. But all of these events happen after the action that triggers the trigger has completed. What…
Month: September 2008
Variables And Parameters
Transact SQL (T-SQL) has two main wait of passing data, variables, and parameters. A variable is an object in T-SQL batches and scripts that can old a value. After you define a variable, you can SET the variable or get the value from a variable at any point after the declaration. Useless trivia: You can…
Flow Control
When you want to build more intelligent or more flexible T-SQL scripts, you’re going to need to know how to control the flow of the program. You’ll need the code to be able to make simple decisions on what to do next. Here are the commands you’re going to learn: IF…ELSE BEGIN…END BREAK CONTINUE WHILE…
The Error Severity
Errors can have different levels of severity. Based on this severity, you may wish to handle the error in different ways (see my articles on TRY..CATCH). In order to determine the severity of an error, Microsoft SQL has provided the ERROR_SEVERITY() function. This function takes no argument and returns an integer. Check out this example:…