Sql 创建视图错误

来源:百度知道 编辑:UC知道 时间:2024/06/30 16:03:47
if not exists(select * from sysobjects where name='V_WaterCorp' and xtype='V')
begin
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
CREATE VIEW [dbo].[V_WaterCorp]
AS
SELECT yearBegin, yearEnd, CorpCode, TradeCode, CorpName, ContorlType
FROM CorpInfo
End

提示:消息 156,级别 15,状态 1,第 6 行
关键字 'VIEW' 附近有语法错误。

错在何处呀?谢谢
begin End之间的SQL脚本时MS SQL2005自动生成的不存在错误,可以正常执行。但加上Begin End之后就有错误了

直接写成CREATE VIEW V_WaterCorp 试试

另外要在之后加入列名[(column1, column2...)]

另外写了begin end之后估计之前写的IF就应该再写ELSE 示例如下:
if (condition)
begin
(statement block)
end
else
begin
statement block)
end
go

create view 后面没有列名啊 哈哈

这样啊

CREATE VIEW [dbo].[V_WaterCorp] (列1,列2,...)
AS
...

谁让你加BEGIN END的