开发者

How can i check in MS SQL Server 2005 if a column is of a specific type

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


You can query the INFORMATION_SCHEMA tables.

E.g.

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


you can use sp_help TableName , it also retrieve's the column's data types and other properties

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜