Thursday 30 March 2017

MS SQL - Fix Error - Incorrect syntax near the keyword 'VIEW'.


Watch this example on YOuTube


Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'VIEW'.

To fix it replace
IF EXISTS (Select * FROM sys.views where name='TestView')
ALTER VIEW [dbo].[TestView]
AS
SELECT        dbo.Companies.*
FROM            dbo.Companies
GO

with

IF EXISTS (Select * FROM sys.views where name='TestView')
Drop View [dbo].TestView
Go
CREATE
VIEW [dbo].[TestView]
AS
SELECT        dbo.Companies.*
FROM            dbo.Companies
GO

No comments:

Post a Comment