2011 T-SQL Tuesdays

T-SQL Tuesday #025 – Invitation to Share Your Tricks

Invitation and followup from Allen White

It doesn’t seem that long ago that having cool little tidbits of information about SQL Server made a huge difference in how effective you could be. Well, that’s still true, but let me give you an example.

SELECT name FROM sysobjects WHERE sysstat & 4 > 0

In the early days of SQL Server, this was the way to pull a list of the names of all the stored procedures in your database. The 4 bit in the sysstat column represented stored procedures. (1 represented user tables and 2 represented view, as I recall, so changing the WHERE clause to read WHERE sysstat & 7 > 0 returned all tables, views and stored procedures.)

As SQL Server has evolved, Microsoft has made it easier to query the metadata to determine what objects existed, adding columns that helped (like ‘Type’ in this case), catalog views, Dynamic Management Objects, etc.

So, the challenge for this month’s T-SQL Tuesday is: What T-SQL tricks do you use today to make your job easier? (Notice I didn’t say PowerShell – I have a bunch of those now, but this is T-SQL Tuesday, not PowerShell Tuesday.)