日期:2014-05-18  浏览次数:20517 次

求指导下面几个语句的意思
刚学数据库,求指导下面几个语句的含义,写上注释。谢谢了
if exists(select * from sysobjects where id=object_id(N'Test1') 
and OBJECTPROPERTY(id, N'IsUserTable') = 1)

------解决方案--------------------
SQL code

if exists(select * from sysobjects where id=object_id(N'Test1')  
and OBJECTPROPERTY(id, N'IsUserTable') = 1)
--你这个不全,应该还有一句
drop table Test1

------解决方案--------------------
SQL code
if exists(select * from sysobjects where id=object_id(N'Test1')  
and OBJECTPROPERTY(id, N'IsUserTable') = 1)

--表示在数据库中存在TEST1的表 IsUserTable=1表示这个表还是用户表,而不是系统表

------解决方案--------------------
查询当前数据库下,是否有一个叫"Test1"的用户表,

如果有,此if条件则成立.
------解决方案--------------------
创建表前判断下是否已经存在此表,如存在,则删除,再建。
------解决方案--------------------
SQL code



---建表语句
if object_id('Test1') is not null 
drop table Test1
go
create table Test1(
 id int identity(1,1) primary key,
 startTime datetime,
 endTime datetime,
 人员 nvarchar(5))

------解决方案--------------------
if exists(select * from sysobjects where id=object_id(N'Test1')
and OBJECTPROPERTY(id, N'IsUserTable') = 1)

exists是判断子查询是否返回记录

子查中的

select * from sysobjects where id=object_id(N'Test1')
and OBJECTPROPERTY(id, N'IsUserTable') = 1
查找到id和表属性是用户表的记录