Category Archives: MS SQL Server

SSIS: Use Two OLE DB Destination Adapters to Catch Insertion/Constraint Errors

If you are using SQL Server Integration Server (SSIS) packages to insert large volumes of data, you have undoubtedly encountered incorrectly formatted or typed data in your data source including precision errors, conversion errors, and primary key/foreign key constraint errors etc. To … Continue reading

Posted in MS SQL Server, SSIS | 1 Comment

MS SQL Server: Quick T-SQL to Delete All User Table Data

Here’s a quick (hack) way to delete all user table data from a Microsoft SQL Server database using the undocumented procedure sp_MSforeachtable. As the name hints, this procedure repeats a SQL statement against all user tables within a database. This … Continue reading

Posted in MS SQL Server, T-SQL | Leave a comment

Creating a SQL CLR User Defined Function

Starting with SQL Server 2005, Microsoft added the awesome ability to reference .Net assemblies from your T-SQL procedures.  Here’s a quick 5 step overview on how to get up and running with your code-based User Defined Function. 1) Create a … Continue reading

Posted in C#, MS SQL Server, T-SQL | Leave a comment

T-SQL: Backup All User Databases

Here’s an easy, generic way to back up all user databases on a SQL Server instance: DECLARE @name VARCHAR(50) — database name DECLARE @path VARCHAR(256) — path for backup files DECLARE @fileName VARCHAR(256) — filename for backup DECLARE @fileDate VARCHAR(20) — … Continue reading

Posted in MS SQL Server, T-SQL | Leave a comment

Shrinking your Transaction Log with SQL Server 2008 to Free Disk Space

If you have been used to clearing up disk space on your development and test SQL server instance file systems with SQL Server 2000 or SQL Server 2005 by using the famous TRUNCATEONLY option on your transaction logs, you might be … Continue reading

Posted in MS SQL Server, T-SQL | Leave a comment

Don’t get caught by ANSI PADDING, VARCHAR, and trailing whitespace!

One thing to be aware of when you have VARCHAR columns and are using ANSI PADDING: trailing whitespace is trimmed and not counted in your equality ( = / <> / LIKE) statements, so you might not get the results you are looking to be … Continue reading

Posted in MS SQL Server, T-SQL | Leave a comment

December 2009 IT Toolbox for TechNet Magazine

The December 2009 TechNet Magazine is on the website. Check out my IT Toolbox column here: December 2009 TechNet Magazine IT Toolbox In this issue I covered: Eraser: Eradicate Sensitive Information SQL Server Backup Pro from Red Gate: Streamline SQL … Continue reading

Posted in Microsoft TechNet, MS SQL Server | Leave a comment

T-SQL: Change Collation on your LIKE Clause Using COLLATE

Ever have trouble matching unicode letter equivalents in your T-SQL queries? For example, when you want “Québec” and “Quebec” to be equivalent in your text search query? This is where specifying Accent Insensative Collation (The “AI” in all those collation codes) comes … Continue reading

Posted in MS SQL Server, T-SQL | Leave a comment

T-SQL Hack to Turn a Set of Row Values into a Delimited String

Ever want to turn multiple rows into a comma separated list when you are querying your database? Here’s a quick way to get it done using “FOR XML PATH(”)”: DECLARE @comma_delimited_list VARCHAR(6000) SELECT @comma_delimited_list = ( SELECT productName + ‘,’ … Continue reading

Posted in MS SQL Server | Leave a comment

Quick Method of Finding Out What Version and Service Pack your SQL Server Instance is Running

If you are looking for a quick way to verify the service pack and version applied to your SQL server instance, try the following T-SQL: SELECT SERVERPROPERTY(’productversion’) AS productversion, SERVERPROPERTY(’productlevel’) AS productlevel, SERVERPROPERTY(’edition’) AS edition Hope this helps!

Posted in MS SQL Server | Leave a comment