SQLServer获取临时表列名并判断指定列名是否存在

if(OBJECT_ID('tempdb.dbo.#tempTB') is not null)
begin
drop table #tempTB;
end

create 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 null
begin
print '不存在列'
end
else
begin
print '存在'
end


drop table #tempTB;

 

posted @ 2019-01-31 15:31  追你追到  阅读(1526)  评论(0编辑  收藏  举报