怎样判断表是否存在 你用的是: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' 查询计算的问题 哪里有可在XP下使用的SQL2005下载? 储存过程的问题啊,谁帮帮忙,谢谢!!! 请问如何将该查询结果横向显示 windows弹窗提示:该内存不能为“written”,是什么意思丫?怎么解决? 包含计算列的表怎么插入数据?急 insert 表 报 no row was produed 请教sql查询问题,进内 请问sql server这句insert into aa(bb)values(N'啊啊')中的N有什么作用 union和cross有什么区别? 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'