读书人

求指导下面几个语句的意思解决方法

发布时间: 2012-02-08 19:52:21 作者: rapoo

求指导下面几个语句的意思
刚学数据库,求指导下面几个语句的含义,写上注释。谢谢了
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 Test1gocreate 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和表属性是用户表的记录

读书人网 >SQL Server

热点推荐