您的位置:首页 > 数据库

如何判断数据库中1个表已经存在,这样不会重复创建一个新表(用sql语句)

2006-09-27 16:38 1191 查看
create Table #tempTable
(
ID int IDENTITY PRIMARY KEY,
bookId int,
bookName varchar(50)
)
go
declare @a int
set @a=(select count(*) as 'aa' from sysobjects where name = '#tempTable')
select @a as 'aaaaaa'
结果为了,临时表是始终为0的

在SQL中判断一个表是否存在

<%sql="if exists (select * from sysobjects where id = object_id(N'[dbo].[phone]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[phone]"
con.execute(sql)
%>
如果表phone存在则删除phone表
其中phone是表名,con是connection对像

<br/>

<hr>

对一个表导出其脚本,里面有例子

<br/>

<hr>

SELECT count(*) <br/> FROM sysobjects <br/> WHERE name = 'jqwm'

<br/>

<hr>

<br/> SELECT count(*) <br/> FROM sysobjects <br/> WHERE name = 'yourtablename' <br/> <br/>

<br/>

<hr>

select count(*) from sysobjects where name = "tablename' and type ='U' <br/> count(*)>=1表示存在

<br/>

<hr>

select count(*) from sysobjects where name = "tablename' and type ='U' <br/> count(*)>=1表示存在 <br/> 或者如IronPromises(铁诺) 的方法,本质上一回事

<br/>

<hr>

同意楼上的 <br/>

SELECT Count(*) AS Qty
FROM MSysObjects
WHERE (((MSysObjects.Name) Like 需判断的已知表名));
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: