Category: Scripts

  • SQL Alphabet Table: Get Next Character

    While writing some dynamic SQL to cycle through a set of Active Directory LDAP queries (don’t ask, ugh) I needed to dynamically create a table with the values 0-9 and A-Z in it.  After a few minutes,

  • Clearing the SQL Server Analysis Services Cache

    Preparing to do some MDX performance testing?  Step one for each and every test should be to clear the cache.  This will ensure you are seeing the performance results without the benefit of having data already loaded up in memory.  How do you empty the MS SQL Analysis Services cache prior to running your query?

  • Free Zip Code, City, County, State, CSV

    Free Zip Code, City, County, State, CSV

    Free Download of the zip code CSV file available at the bottom of this post. Why this is so hard to track down I don’t know.  We were looking for a comma delimited list which would map zip code to county since county is the lowest grain available in the out of the box SQL […]

  • SQL Server Partition Lock Escalation Property Query

    Whenever I want to check a setting in SQL Server I always prefer to find it using a query.  Every once in awhile these settings turn out to be on the verge of being undocumented.  This is the case with table level lock escalation (also known as partition level lock escalation).  The T-SQL query below […]

  • Find User’s Default Schema

    Need to find the default schema for a user in MS SQL?  Need to confirm all your SQL Server users default schema’s are set correctly?  Easy peasey.  Run the following query and enjoy.

  • Find Tables Without Clustered Indexes

    Need a way to find all tables without a clustered index in SQL Server? Running this script every once in awhile will help ensure best practices are being followed and every table has a clustered index. This script is compatible with SQL Server 2005 and SQL Server 2008.

  • SQL Server – Get Proc Name From Within Proc

    Use this system function and variable to get the name of a stored procedure from within the procedure itself. The Object Id can also be returned.

  • Enable xp_cmdshell in SQL Server 2008

    Enable xp_cmdshell with a few lines of T-SQL. Fast and Easy!

  • SQL Server Combine MDF Files – The Easy Way

    Do you need to combine or merge two data files (MDF or NDF)?  There are a number of complicated options available or you can use the two lines of code below to do the trick… It’s up to you.  This method works with both SQL Server 2005 and SQL Server 2008.

  • SQL Server Rebuild Indexes – The Fastest Way

    Want to rebuild all the indexes in your MS SQL database?  The script below will rebuild all the indexes in your SQL Server 2008 or SQL Server 2005 (SP2) database and offers a number of enhancements that make this the best SQL Server index rebuild script in all the land and the first choice of […]