怎样判断表是否存在 你用的是:SQL-Server2000吗?是:你可以直接在企业管理器里看到。不是:你可以用SQL语言查找,看有没有。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select name from sysobjects where uid = (select uid from sysusers where name='username') 以查找表名为employee的用户表为例:if exists(select * from sysobjects where objectproperty(object_id('employee'), 'isusertable') = 1) //employee表存在else //employee表不存在 直接使用SQL语言来查询,如果存在该表,则不会出现错误提示,但是如果不存在该表。肯定出现错误提示。不管是在Oracle的SQLplus里还是SQL Server里的查询分析器里。你都可以使用SQL语句来查询。 if exists (select * from dbo.sysobjects where id = object_id(N'TableName') ) if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TA1001]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)drop table [dbo].[TA1001] 系统表sysobjects中存有所有数据库表名。用select语句就行。 select * from user_objects where lower(object_name)='表的名字' /****** Object: Table [dbo].[ccc] Script Date: 02-11-5 18:26:54 ******/if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ccc]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)drop table [dbo].[ccc]GO/****** Object: User dbo Script Date: 02-11-5 18:26:50 ******//****** Object: Table [dbo].[ccc] Script Date: 02-11-5 18:26:59 ******/CREATE TABLE [dbo].[ccc] ( [born] [datetime] NULL , [age] AS (datediff(year,[born],getdate())) ) ON [PRIMARY]GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ccc]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) if OBJECTPROPERTY(object_id('TableName'), N'IsTable') = 1print 'exists'elseprint 'not exists' 帮我看看这条SQL语句怎么修改一下效力会高些? 用ODBC配置连接SQL2008出错,怎么办呢 TXT导入到表中后,顺序不对 关于数据库端口问题求教? sql 中的 自定义函数中调用自定函数 不行吗? 如何创建这样的数据库视图? sql语句求助 请问这样的存储过程怎么写? 我的数据库不定期把一些原始数据进行了恢复(谢谢先) 怎样比较时间在1分钟以内的? HELP!! 学sql不久,对SQL不是很熟,求一SQL SERVER备份和恢复的源码,好急!
//employee表不存在
drop table [dbo].[TA1001]
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ccc]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[ccc]
GO/****** Object: User dbo Script Date: 02-11-5 18:26:50 ******/
/****** Object: Table [dbo].[ccc] Script Date: 02-11-5 18:26:59 ******/
CREATE TABLE [dbo].[ccc] (
[born] [datetime] NULL ,
[age] AS (datediff(year,[born],getdate()))
) ON [PRIMARY]
GO
print 'exists'
else
print 'not exists'