在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同理判断,首先判断查询结果是否存在,如果存在执行判断后面的语句,查询的数据库,表,列的方法相同;
deepin20怎么新增字体? deepin20安装字体的教程
Linux如何给文件权限? linux给文件添加可执行权限的技巧
deepin20桌面图标样式怎么修改? deepin更换图标主题的技巧
virtualbox打不开虚拟机怎么办? linux无法访问virtualbox的解决办法
deepin怎么注销系统? deepin系统注销与切换用户的方法
Manjaro linux怎么调鼠标速度? Manjaro鼠标设置光标速度的技巧