问题
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