22,300
社区成员




if exists(select object_id('tt'))
drop table tt
drop table if exists address_book;这句SQL语句是什么意思
悬赏分:10 - 解决时间:2009-7-17 09:36
我备份的SQL语句中有这么一行,不知道是什么意思?
提问者: QQ41678438 - 二级最佳答案如果数据库中存在address_book表,就把它从数据库中drop掉。
备份sql中一般都有这样的语句,如果是数据库中有这个表,先drop掉,然后create表,然后再进行数据插入。
'网上竟然也有“drop table if exists **”这样的写法,不知道是什么数据库中的语句??'
if object_id('dbname..tbname') is not null
drop table tbname
go
if exists(select 1 from sysobjects where name='tbname' and xtype='u')
drop table tbname
go
或这样if object_id('dbname..tbname') is not null
drop table tbname
go
if object_id('tbname','u') is not null
drop table tbname
go
if object_id('tbname') is not null
drop table tbname
go