Visual Studio thinks correct SQL syntax is incorrect

In my case I was adding already existing post deployment script(.sql file) by clicking on a folder named "Reference Data" ==>Add Existing Item==>Select List of .sql files including the Script.PostDeployment1.sql file. On pressing F5 it was giving following error:

SQL46010: Incorrect syntax near :.

contents of sql file were :

:r ".\Customer.data.sql"
GO

:r ".\Product.data.sql"
GO

:r ".\OrderType.data.sql"
GO

:r ".\Orders.data.sql"
GO

Solution: Post Deployment script should be created using VS.In existing project,open Visual studio and add post deployment script by clicking on : Add==>New Item ==>Script ==>Post Deployment Script ==>.PostDeployment1.sql.After creating PostDeployment1.sql file simply copy paste your content an then press F5..PostDeployment1.sql should execute correctly without any error.


There is a setting in the project properties called Target platform that tells VS what version of SQL Server to check the syntax against.

These are relatively new additions to the T-SQL syntax, and they might not work if the syntax was set to e.g. SQL Server 2005.

Visual Studio 2013 database project settings


Old thread but this did catch me out so I thought I'd share my experience, the documentation for ALTER ROLE seems to indicate that it is supported on SQL 2008 when in fact only part of the functionality is. You can use Alter Role to change the name of a Role i.e. ALTER ROLE [ROLE NAME] WITH [NEW ROLE NAME] But to add or remove members from the role it is necessary to use the old (and now deprecated) stored procedure sp_addrolememeber i.e. sp_addrolemember 'Role Name', 'User Name'.
As Aaroninus points out if you target SQL 2012 or later this will not report as an error.