简体   繁体   中英

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.

Eg

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

您可以使用sp_help TableName ,它也可以检索列的数据类型和其他属性

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM