declare @cou int select @cou=count(*) from sysobjects where xtype = 'v' and name ='视图名' if @cou >0 print '已存在视图' else create view as select * from tab where ...
这个查询写法select @cou=count(*) from sysobjects where xtype = 'v' and name ='视图名'是2005的,如果是2000,则是select @cou=count(*) from sysobjects where type = 'v' and name ='视图名'
先谢谢, 我试了下,在SQL2005查询分析器中运行不成呀。说是view附近有错误!
if object_id('dbo.v_name','v') is not null return; create view dbo.v_name as select ... ...
declare @cou int
select @cou=count(*) from sysobjects where xtype = 'v' and name ='视图名'
if @cou >0
print '已存在视图'
else
create view as
select * from tab
where ...
这个查询写法select @cou=count(*) from sysobjects where xtype = 'v' and name ='视图名'是2005的,如果是2000,则是select @cou=count(*) from sysobjects where type = 'v' and name ='视图名'
我试了下,在SQL2005查询分析器中运行不成呀。说是view附近有错误!
if object_id('dbo.v_name','v') is not null
return;
create view dbo.v_name
as
select ... ...
消息 111,级别 15,状态 1,第 3 行
'CREATE VIEW' 必须是查询批次中的第一个语句。
if object_id('dbo.v_name','v') is not null
return;
go
create view dbo.v_name
as
select ... ...
go
{
退出;
}
else
{
exec ('建立name视图的SQL')
}