如果我们的语句为:
IF NOT EXISTS(SELECT 1 FROM sys.views WHERE name='Report_IndividualTicket')
BEGIN
create view Report_IndividualTicket
as
SELECT Ticket.TicketNumber, Ticket.TicketID,
GisProcess.StageName,
Content.DtReceived, Content.ContentText
FROM
(GisProcess INNER JOIN Ticket
ON GisProcess.TicketID=Ticket.TicketID)
INNER JOIN Content
ON Ticket.ContentID=Content.ContentID
END
会提示以下错误:
Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'view'.
出现这个错误的原因是:create view 这一句必须是批处理中的第一句。
所以可以将该语句修改为:
IF EXISTS(SELECT 1 FROM sys.views WHERE name='Report_IndividualTicket')
DROP VIEW Report_IndividualTicket
GO
create view Report_IndividualTicket
as
SELECT Ticket.TicketNumber, Ticket.TicketID,
GisProcess.StageName,
Content.DtReceived, Content.ContentText
FROM
(GisProcess INNER JOIN Ticket
ON GisProcess.TicketID=Ticket.TicketID)
INNER JOIN Content
ON Ticket.ContentID=Content.ContentID
GO
您可能感兴趣的文章:- Mysql判断表字段或索引是否存在
- sql server中判断表或临时表是否存在的方法
- mysql判断字段是否存在的方法
- SQL判断字段列是否存在的方法
- mysql中判断记录是否存在方法比较
- mySQL count多个表的数据实例详解
- sql中count或sum为条件的查询示例(sql查询count)
- SQL判断是否"存在",还在用 count 操作?很耗时的!