Skip to content

Instantly share code, notes, and snippets.

@jpierson
Last active February 28, 2017 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpierson/f04e24fcbfe3e92558076acbdc2b88f8 to your computer and use it in GitHub Desktop.
Save jpierson/f04e24fcbfe3e92558076acbdc2b88f8 to your computer and use it in GitHub Desktop.
T-SQL Tips

T-SQL Tips

Get definitions for all stored procedures and functions for a database

Getting the definitions can be useful when attempting to locate specific constants or dynamic usage of other database objects such as functions or tables.

select p.[name], s.[definition]
from sys.procedures p
   inner join sys.sql_modules s on p.[object_id] = s.[object_id]
order by p.[name]

Get definitions for all triggers for a database

select p.[name], s.[definition]
from sys.triggers p
   inner join sys.sql_modules s on p.[object_id] = s.[object_id]
order by p.[name]

Enable xact_abort by default for entire database

EXEC sp_configure 'user options', 16384
reconfigure

To test whether this option is already set use @@options. Note that this will be true whether the above database wide defaults setting is used or xact_abort is set using set xact_abort on at the session level.

if ( (16384 & @@options) = 16384 ) printt 'XACT_ABORT'

Additionally other options can also be set at the database level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment