I've tried a few different google searches but can't find any best practices or tutorials that address this.
This is the first time I've used a VS database project. I've imported an existing database (everything looks fine) and now I want to populate some of the tables post-deployment.
There is a Script.PostDeployment.sql
file that includes the following header:
/*
Post-Deployment Script Template
--------------------------------------------------------------------------------------
This file contains SQL statements that will be appended to the build script.
Use SQLCMD syntax to include a file in the post-deployment script.
Example: :r .\myfile.sql
Use SQLCMD syntax to reference a variable in the post-deployment script.
Example: :setvar TableName MyTable
SELECT * FROM [$(TableName)]
--------------------------------------------------------------------------------------
*/
I'm wondering if from the last three lines there is some expected way to write these scripts using variables instead of just pure T-SQL syntax?
Should I be writing
INSERT INTO [dbo].[BlackAdder] VALUES ('edmund')
INSERT INTO [dbo].[BlackAdder] VALUES ('baldrick')
or
setva开发者_如何学Gor [dbo].[BlackAdder] BlackAdder
INSERT INTO [$(BlackAdder)] VALUES ('edmund')
INSERT INTO [$(BlackAdder)] VALUES ('baldrick')
Does the latter allow some sort of compile-time check so that if setvar
cannot resolve [dbo].[BlackAdder]
that the project will give me some error?
If you open the project Properties
folder, and click on Database.sqlcmvars
you will see 3 vars already defined $(DefaultDataPath),
$(DtabaseName)
and $(DefaultLogPath)
and can define your own here.
The setvar would be the other way around:
:setvar BlackAdder [dbo].[BlackAdder]
but ideally you define these in Database.sqlcmvars
.
The intended use is for deploying your database project into multiple environments by defining SQLCMD variables and including them in your pre-deployment and post-deployment scripts.
How to: Define Variables for Database Projects
Property Files in Database and Server Projects
精彩评论