Skip to main content

Show deprecated SQL Server Data Types

From SQL Server version 2008 forward the data types text, ntext and image have been deprecated. The code below will cursor through all the user databases on your server and bring back the database, tables and columns that use these data types, if they exist.

-- Find Deprecated datatypes in all databases
USE master;

IF EXISTS (SELECT 1 FROM tempdb..sysobjects WHERE id=OBJECT_ID('tempdb..#DataTypes')) DROP TABLE #DataTypes
    DBName VARCHAR(50)
    ,TableName VARCHAR(100)
    ,ColName VARCHAR(100)
    ,ExistingDataType VARCHAR(20)
    ,ChangeToDataType VARCHAR(20)

Declare @DBName VARCHAR(50);

        SELECT Name from sysdatabases where name not in ('master','model','msdb','tempdb') order by name

OPEN DeprecatedDTCur
       PRINT 'Processing Database: ' + @DBName;
         SET @SQL = 'USE [' + @DBName + '];
         INSERT #DataTypes
                DB_Name() AS DBName
                ,O.NAME  AS TableName
                 ,col.NAME AS ColName
                 ,systypes.NAME    AS ExistingDataType
                 ,CASE systypes.NAME
                       WHEN ''text'' THEN  ''VARCHAR(MAX)''
                       WHEN ''nText'' THEN ''nVARCHAR(MAX)''
                       WHEN ''Image'' THEN ''VARBINARY(MAX)''
                 END AS ChangeToDataType
FROM syscolumns col
INNER JOIN sysobjects O
       ON =
INNER JOIN systypes
       ON col.xtype = systypes.xtype
WHERE O.Type = ''U''
       AND ObjectProperty(o.ID, N''IsMSShipped'') = 0
       AND systypes.NAME IN (
          --PRINT (@SQL)
          EXEC (@SQL)
        FETCH NEXT FROM DeprecatedDTCur INTO @DBName;
CLOSE DeprecatedDTCur;

SELECT * FROM #DataTypes;



Popular posts from this blog

How to move the Microsoft Assessment and Planning Toolkit (MAP) database to a different drive

The Microsoft Assessment and Planning Toolkit (MAP) is a very useful tool for scanning your network to find instances of SQL Server plus all manner of detailed information about the installed product, OS and hardware it sits on.

<Click image to enbiggen>
There is an issue with it the database it uses to store the data it collects, however. Assuming you don't have an instance called MAPS on your server, the product will install using LocalDB (a cut down version of SQL Server Express) and puts the databases on your C: drive. If you then scan a large network you could easily expand the database to 10GB which may cause issues on a server when that drive is often one of the smallest. However, there is a simple solution: connect to LocalDB using Management Studio, detach the databases, move to a different drive, set permissions on the new location if required and reattach the database. How do you connect to LocalDB? Here you go:

Connect to (localdb)\MAPTOOLKIT

The databases I move…

SSIS Job fails when it calls Excel via the SQL Agent but succeeds from SSDT

If you have an SSIS package which fails when run on a schedule but succeeds when executed interactively in Visual Studio/BIDS/SSDT, it may produce an error like this:
Executed as user: DOMAIN\user. Microsoft (R) SQL Server Execute Package Utility  Version 12.0.4100.1 for 64-bit  Copyright (C) Microsoft Corporation. All rights reserved.    Started:  10:52:25  Error: 2017-02-06 10:52:26.26     Code: 0x00000001     Source: Open Spreadsheet and Run Macro      Description: Exception has been thrown by the target of an invocation.  End Error  DTExec: The package execution returned DTSER_FAILURE (1).  Started:  10:52:25  Finished: 10:52:26  Elapsed:  0.485 seconds.  The package execution failed.  The step failed.
The issue is a type of permissions error. Excel needs to have its permissions changed via the DCOM applet in Control Panel. By default it is on “The launching user.” This needs to be changed to a user with more permissions, in this case we have used the service account used by SQL A…

SAN performance testing using SQLIO

This document describes how to use Microsoft’s SQLIO to test disk/SAN performance. It is biased towards SQL Server – which uses primarily 64KB and 8KB data pages so I am running the tests using those cluster sizes, however, other sizes can be specified.  Download SQLIO from SQLIO is a command line tool with no GUI so you need to open a command prompt at C:\Program Files (x86)\SQLIO after you have installed it. Configuration First of all edit param.txt so that you create the test file we will be using. The file needs to be bigger than the combined RAID and on-board disk caches. In this case we are using a 50GB file.
The “2” refers to the number of threads to use when testing, you don’t need to change this now. The “0x0” value indicates that all CPUs should be used, which you probably don’t want to change either, “#” is a comment. The only part you may want to change is 51200 (50GB) and the drive letter. After …