views:

12

answers:

1

Hi,

I want to change the type of a column in MS SQL Server 2005, but before i change the type of that column i want to check if that column is of the type i want to change. How can i do that in SQL?

Thanxs, Bas Hendriks.

Based on the anwser i wrote the following query that did the trick:

        IF NOT EXISTS (SELECT *
            FROM INFORMATION_SCHEMA.COLUMNS
            WHERE TABLE_NAME = 'e_application'
            AND COLUMN_NAME = 'txt_locked_by'
            AND DATA_TYPE = 'nvarchar'
            AND CHARACTER_MAXIMUM_LENGTH = 15 )
        BEGIN
            ALTER TABLE.....
        END
+1  A: 

You can query the INFORMATION_SCHEMA tables.

E.g.

SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'MyTable'
RedFilter