SQL语句判断数据库、表、字段是否存在
2015-09-30 13:45
656 查看
--判断[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不存在'
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不存在'
相关文章推荐
- redis 配置说明
- memcache原理
- SQL Serverver -- 创建财政年度表 (约束)
- 12. 查询数据库账号的所有权限
- 数据库规范
- Oracle多行函数/组函数
- Oracle Study之--Oracle 11g RAC故障(Failed to create or upgrade OLR)
- StackExchange.Redis 使用 - 事件(五)
- Oracle Study之--Oracle 11g RAC故障(Failed to create or upgrade OLR)
- redis的备份
- 数据库(关系型)设计三大范式
- mysql多实例添加
- redis安装、配置、命令
- SDE ST_Geometry SQL st_intersects查询很慢的解决方法
- select into from与insert into select区别详解,sql语句复制表
- SQL优化
- oracle完整卸载,四步曲
- Mysql ——1045-Access denied for user 'root'@'localhost'(using password:YES)
- sqlServer 取每组的前几条数据
- spring集成redis cluster