您的位置:首页 > 数据库

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

2014-04-25 09:47 597 查看
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
)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐