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

☆樱花仙子☆ 提交于 2019-12-24 00:14:28

问题


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:


You can query the INFORMATION_SCHEMA tables.

E.g.

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



回答2:


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



来源:https://stackoverflow.com/questions/3855446/how-can-i-check-in-ms-sql-server-2005-if-a-column-is-of-a-specific-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!