最新下载
热门教程
- 1
 - 2
 - 3
 - 4
 - 5
 - 6
 - 7
 - 8
 - 9
 - 10
 
sqlserver中if exists和if not exists关键字用法
时间:2022-06-29 07:53:21 编辑:袖梨 来源:一聚教程网
在sql语名中,if not exists 即如果不存在,if exists 即如果存在。
下面学习下二者的用法。
a,判断数据库不存在时
 
if not exists(select * from sys.databases where name = 'database_name')
b,判断表不存在时
 
if not exists (select * from sysobjects where id = object_id('table_name') and OBJECTPROPERTY(id, ’IsUserTable’) = 1)
c,判断列不存在
 
if not exists (select * from syscolumns where id=object_id(’table_name’) and name=’column_name’)
当判断的表不存时,我可以执行创建数据库,创建表,增加列,可以执行相应的SQL语句;
而if exists同理判断,首先判断查询结果是否存在,如果存在执行判断后面的语句,查询的数据库,表,列的方法相同;
相关文章
- 我的世界创造模式快捷栏怎么保存 mc物品栏管理技巧 11-04
 - 我的世界怎么重新加载区块 mc显示错误技巧解决方法 11-04
 - 我的世界超级敌对模式是什么 mc特殊事件机制说明 11-04
 - 快来当领主阿瑞斯强度怎么样 11-04
 - 命运圣契伊丽丝技能效果如何 11-04
 - 镭明闪击塔攻怎么玩 11-04