如果我们的语句为:IFNOTEXISTS(SELECT1FROMsys.viewsWHEREname='Report_IndividualTicket')BEGINcreateviewReport_IndividualTicketasSELECTTicket.TicketNumber,Ticket.TicketID,GisProcess.StageName,Content.DtReceived,Content.ContentTextFROM(GisProcessINNERJOINTicketONGisProcess.TicketID=Ticket.TicketID)INNERJOINContentONTicket.ContentID=Content.ContentIDEND会提示以下错误:Msg156,Level15,State1,Line4Incorrectsyntaxnearthekeyword'view'.出现这个错误的原因是:createview这一句必须是批处理中的第一句。所以可以将该语句修改为:IFEXISTS(SELECT1FROMsys.viewsWHEREname='
如果我们的语句为:
IF NOT EXISTS(SELECT 1 FROM sys.views WHERE name='Report_IndividualTicket')BEGINcreate view Report_IndividualTicketasSELECT Ticket.TicketNumber, Ticket.TicketID,GisProcess.StageName,Content.DtReceived, Content.ContentTextFROM(GisProcess INNER JOIN TicketON GisProcess.TicketID=Ticket.TicketID)INNER JOIN ContentON Ticket.ContentID=Content.ContentIDEND
会提示以下错误:
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_IndividualTicketGOcreate view Report_IndividualTicketasSELECT Ticket.TicketNumber, Ticket.TicketID,GisProcess.StageName,Content.DtReceived, Content.ContentTextFROM(GisProcess INNER JOIN TicketON GisProcess.TicketID=Ticket.TicketID)INNER JOIN ContentON Ticket.ContentID=Content.ContentIDGO
标签: 视图 SQLSERVER 判断 是否 存在 后再 创建 语句
声明:本文内容来源自网络,文字、图片等素材版权属于原作者,平台转载素材出于传递更多信息,文章内容仅供参考与学习,切勿作为商业目的使用。如果侵害了您的合法权益,请您及时与我们联系,我们会在第一时间进行处理!我们尊重版权,也致力于保护版权,站搜网感谢您的分享!