【SQL】SQLServer判断表,列是否存在

2020-08-17 17:31:46  阅读 3281 次 评论 0 条

判断实体表是否存在

if Exists(select top 1 * from sysObjects where Id=OBJECT_ID(channels') and xtype='U')
    print 'yes'
else 
    print 'no'

判断临时表是否存在

if exists (select * from tempdb.dbo.sysobjects where id = object_id(N'tempdb..#TempUsers') and type='U')
    print 'yes'
else 
    print 'no'

判断列是否存在(channelid是否存在于channeld)

if exists(select * from syscolumns where id=object_id('channels') and name='channelid' 
collate Chinese_PRC_CI_AI_WS)
begin 
print 'yes'
end
else
begin 
print 'no'

end



微信扫码查看本文
本文地址:https://www.yangguangdream.com/?id=2095
版权声明:本文为原创文章,版权归 编辑君 所有,欢迎分享本文,转载请保留出处!

发表评论


表情

还没有留言,还不快点抢沙发?