if(OBJECT_ID('tempdb.dbo.#tempTB') is not null)
begin drop table #tempTB;endcreate table #tempTB(
ID int NULL,Name nvarchar(50) NULL,Pwd varchar(50) NULL)--查询所有列名
select name from tempdb.sys.columns where object_id = OBJECT_ID('tempdb.dbo.#tempTB')--查询定义的列长度(以字节为单位)select COL_LENGTH('tempdb.dbo.#tempTB','ID')--判断表中是否包含列if COL_LENGTH('tempdb.dbo.#tempTB','ID') is nullbegin print '不存在列'endelsebegin print '存在'end drop table #tempTB;