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;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM