Tag: script

  • Alter Table: Add Not Null Column – SQL Server

    Listen up my people.  NOT NULL columns are your friend.  It may take a few extra brain cells to populate it initially but the long term rewards in data quality are well worth it. (You’ll also force all your software developer cohorts to think specifically about the values they’ll be inserting into a column which […]

  • SQL Script: Distinct Column Values Across All Tables

    Sometimes I wonder if some of the more random scripts I post are useful to anyone but me so if this one is useful to you definitely drop a comment below! Check it out:  Our team was trying to confirm what our best practice was when creating flag columns in the data warehouse.  As usual […]

  • SQL: Create Schema If Not Exists

    When deploying code I try to create my scripts so they can be rerun without an error being thrown (e.g. “object already exists”).  There’s some fancy word for this that I used to try and use so as to appear ostentatious but it turns out people found me ostentatious even when I didn’t use the […]

  • SQL Server Management Studio: Recover Lost Files

    Nooooooooo!  Power outage+unsaved files SQL Server Management Studio files=Panic!!!  Wait a sec.  Don’t panic.  Every modern application, especially Microsoft apps, prompts you after a crash and asks you if you want to recover your lost files right?  Right!?!  Somehow, SSMS does NOT include this feature.  Why?  No idea.  Blame Management Studio’s stability.  It rarely shutsdown […]

  • 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 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 Row Count – The Fastest Way

    What’s the fastest way to get the number of rows in a table on SQL Server 2005 or SQL Server 2008? Use the code the pros use.