[SQL] 如何在SQL Server2005数据库中检查一个表是否存在,如存在就删除表记录,如不存在就建表.
Posted on 2014-04-25 09:47 beeone 阅读(1740) 评论(0) 编辑 收藏 举报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 )