用该语句判断 if exists(select 1 from sysobjects where xtype='u' and name='表名') print 'aaa' else print 'not exists'
select count(*) from sysobjects where name = '表名';如果count > 0就说明存在该表。
if exists (select * from dbo.sysobjects where id = object_id(N'[tablename]') print "存在该表"
if objects_id('表名') is not NULL and exists(select 1 from dbo.sysobjects where name ='表名') begin ......... print '存在该表' end
建议用OBJECT_ID来判断(避免同其他OBJECT也同名) if object_id(N'[Utable]') is not NULL create table Utable(.........)
use 库名 if IsNull(Object_ID('aa'),0)<>0 Print '表存在' else Print '表不存在'
if exists (select * from dbo.sysobjects where id = object_id(N'[tablename]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)在系统表sysobjects中记录了数据库中所有的表,包括系统表 在系统表syscolumns中记录了数据库中所有表中的所有字段
if object_id('表名') is not NULL 就可以了
if exists(select * form dbo.sysobjects where id = object_id('tableName') and xtype='U') print 'true' or if object_id('tableName') is not null print 'true'
declare @TableName varchar(50) select @TableName='author' if object_id(@TableName) is not null print 'true' else print 'false'
if exists(select 1 from sysobjects where xtype='u' and name='表名')
print 'aaa'
else
print 'not exists'
where id = object_id(N'[tablename]')
print "存在该表"
where name ='表名')
begin
.........
print '存在该表'
end
if object_id(N'[Utable]') is not NULL
create table Utable(.........)
if IsNull(Object_ID('aa'),0)<>0
Print '表存在'
else
Print '表不存在'
在系统表syscolumns中记录了数据库中所有表中的所有字段
就可以了
print 'true'
or
if object_id('tableName') is not null
print 'true'
select @TableName='author'
if object_id(@TableName) is not null
print 'true'
else
print 'false'
如果事临时表在tempdb中。
sysobjects
在数据库内创建的每个对象(约束、默认值、日志、规则、存储过程等)在表中占一行。只有在 tempdb 内,每个临时对象才在该表中占一行。