SQL Server project running multiple script post deployments

I have a SQL Server 2008 database project, and I want to run several scripts so that, after posting.

I added a script to the scripts folder PostDeploy.Sqland noted how PostDeploy, and this works fine. I know that only one script can be marked as post deploy; so I thought I could do it in a script:

-- Post Deploy stuff
SELECT * FROM MYTABLE
GO

:r RunPostDeploy2.sql
GO

Where RunPostDeploy2.sqlis in the same directory as the link. I tried to copy the file locally, but the problem seems to be to use :r.

Is it possible to call external scripts from post-deployment in this way, and if so, how?

+4
source share
2 answers

You need to turn your script into SQLCMD mode. There is a toolbar button on the top of the file.

enter image description here

Or you can do it by going to

enter image description here

+6
source

First, you can only install one script as "post deploy" (usually configured for you in older DB projects).

When using a post-deployment script, you include others using:

:r .\MyScript1.sql
:r .\MyScript2.sql
:r .\NestedFolder1\MyScript25.sql
--etc

It looks like you are missing the “. \” That tells the launch command to look in this folder.

+4
source

Source: https://habr.com/ru/post/1536933/


All Articles