SQL语句判断指定的数据库、表、字段、存储过程是否存在
直接上代码,对大家有用就好!
代码
--判断[TestDB]是否存在
ifexists(select1frommaster..sysdatabaseswherename='TestDB')
print'TestDB存在'
else
print'TestDB不存在'
--判断表[TestTb]是否存在
ifexists(select*fromTestDB..syscolumnswhereid=object_id('TestDB.dbo.TestTb'))
print'表TestTb存在'
else
print'表TestTb不存在'
--判断[TestDB]数据中[TestTb]表中是否存在[Name]字段
ifexists(select*fromTestDB..syscolumnswhereid=object_id('TestDB.dbo.TestTb')andname='Name')
print'字段Name存在'
else
print'字段Name不存在'
If exists(select name from sysobjects where name='存储过程名' and type='p')
drop proc 存储过程名 posted on -09-27 17:38 搏击的小船 阅读(...) 评论(...) 编辑 收藏
如果觉得《SQL语句判断指定的数据库 表 字段 存储过程是否存在》对你有帮助,请点赞、收藏,并留下你的观点哦!