[SQL] 如何在SQL Server2005数据库中检查一个表是否存在,如存在就删除表记录,如不存在就建表.

1. 检索 dbo.sysobjects表,
select count(*) from dbo.sysobjects
where xtype='U' and Name = '你的表名'
 
2. 根据返回的结果判断表是否存在,确定是清楚表的记录,还是建表
-判断t表是否存在,存在删除
declare @num int
set @num=0
select @num=count(*) from dbo.sysobjects where xtype='U' and Name = 't'
if(@num>0)
begin
    drop table t
    
end
GO
--创建T表
create table t
(
    a int,
    b int
)
原文地址:https://www.cnblogs.com/beeone/p/3687963.html