Category: DBA

  • Easy SQL Server Snapshot Script / Proc

    Man!!!! Why is the code to create a database snapshot so ridiculously complicated? Actually, I guess I understand why but how about allowing it to be done through SSMS and then setting a bunch of the parameters as defaults for us? Come on Microsoft! Help a SQL brother out! Well luckily, where Microsoft fails, I’m […]

  • SSDT VS 2012 – Bringing an existing database under source control

    Alright! You are the hero of your database team! You’ve received the okay to start using SQL Server Data Tools to manage one of your existing databases. You think to yourself: “Within a few minutes I’ll have the project up and running and I can move on to phase 2 of my plan to save […]

  • Error when trying to use DAC connection in SQL Server

    So, one of my local databases got stuck in single-user mode. Easy solution? Connect to my instance using SQL Server’s Dedicated Admin Connection (aka DAC) and flip the database back to multi-user. Easy! Wait. What? TITLE: Connect to Database Engine —————————— Cannot connect to ADMIN:localhost\SQL2012. —————————— ADDITIONAL INFORMATION: A network-related or instance-specific error occurred while […]

  • SQL Job Steps And Run_Duration: The query that formats run_duration correctly and doesn’t make you want to shoot your eye out

    Ever tried to figure out how long a step for a particular SQL Server job takes? You can of course get it from the Management Studio, but we’re database people! We want to see the trend over time not just a point in time! We want to write queries! Hooray for data! You do a […]

  • SQL Query: To Find Which Columns An Index Is On

    Do you need to write a SQL Server query to find out which columns an index is on? Do you have an index name but need to use T-SQL to determine the column names? Not a problem! The query below will qive you exactly what you want. The example uses an AdventureWorks index as the […]

  • SQL Query: List All Indexes And Their Columns

    Looking to write a SQL query which will list out all the indexes in your database as well as the columns in the index? Well my friend you’ve come to the right place. The query below will give list out the following information: Schema Table Name (or view) Index Name Is Primary Key Is Unique […]

  • Escaping From An Underscore In A SQL Server Wildcard / LIKE Search

    There are two different ways to perform a wildcard (aka LIKE) search in SQL Server to find a word with an “_” underscore. Both options are outlined at the end of the article after a reference to the cult classic Mystery Science Theater 3000: Escape From The Bronx.

  • Parse and sort SET STATISTICS IO output with Excel

    I wish I could say this was my idea. Somebody posted it on twitter awhile back and I did the classic “facepalm”. I have no idea how many times I manually picked apart the results of SQL Server’s SET STATISTICS IO ON without considering creating a formula to handle it for me. So, somebody came […]

  • Set DATA_COMPRESSION for all tables

    Working on a quick little project to sync up two databases and I realized the data compression was set differently between the two of them. Apparently, my Google fu was not up to snuff because it took quite a bit of stumbling around to find a forum post matching what I wanted to do.  There […]

  • Last Restore Date And Time – SQL Server Query

    “How old is this data?” “When was this database restored?” “How old is this backup?” These are common question in development environments.  A fast little t-sql query can tell you the following: The date and time of the last restore. The date and time the backup which was restored was originally taken. The user who […]