我在 visual studio 中有 sql 项目,我创建了预部署脚本
/*
Pre-Deployment Script Template
--------------------------------------------------------------------------------------
This file contains SQL statements that will be executed before the build script.
Use SQLCMD syntax to include a file in the pre-deployment script.
Example: :r .\myfile.sql
Use SQLCMD syntax to reference a variable in the pre-deployment script.
Example: :setvar TableName MyTable
SELECT * FROM [$(TableName)]
--------------------------------------------------------------------------------------
*/
:setvar TableName MyTable
SELECT * FROM [$(TableName)]
:setvar
但我在线上遇到错误
Incorrect syntax near ':'.
我错过了什么?
社区维基答案:
您需要通过菜单SQL > Execution Settings
SQLCMD
切换到Visual Studio 模式。SQLCMD mode
如果您深入了解Options > SQL Server Tools > Query Execution ,您还可以默认打开所有 SQL 文件。