文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>SQL语句判断数据库、表、字段是否存在

SQL语句判断数据库、表、字段是否存在

时间:2010-09-28  来源:moss_tan_jun


--判断[TestDB]是否存在
if exists(select 1 from master..sysdatabases where name='TestDB')
    print 'TestDB存在'
else
    print 'TestDB不存在'

--判断表[TestTb]是否存在
if exists(select * from TestDB..syscolumns where id=object_id('TestDB.dbo.TestTb'))
    print '表TestTb存在'
else
    print '表TestTb不存在'

--判断[TestDB]数据中[TestTb]表中是否存在[Name]字段
if exists(select * from TestDB..syscolumns where id=object_id('TestDB.dbo.TestTb') and name='Name')
    print '字段Name存在'
else
    print '字段Name不存在'
相关阅读 更多 +
排行榜 更多 +
我爱点点学英语

我爱点点学英语

学习教育 下载
最高速公路赛车

最高速公路赛车

体育竞技 下载
公路赛车pro

公路赛车pro

体育竞技 下载