DoomerDGR8
DoomerDGR8

Reputation: 5042

Can I call different SQL Scripts from within the VS Database project's post-deployment script

I have a massive insertion operation on a number of tables for a base-line database. I was trying to organize this task in multiple SQL scripts for individuals tables and dependent tables. I need to call the scripts in a sequence from the main post deployment SQL script.

Any ideas?

Upvotes: 4

Views: 1723

Answers (1)

Keith
Keith

Reputation: 21224

  1. If there isn't already a post-deployment script in your project (possibly called Script.PostDeployment.sql) then add a new item of type SQL Server > User Scripts > Post-Deployment Script.

  2. In this script, reference your insert scripts using a relative path like below. The scripts will be run in the order you list them. Example:

:r .\InsertScripts\script1.sql

:r .\InsertScripts\script2.sql

(Ignore any errors/warnings that say this is invalid syntax. Visual Studio treats these like placeholders and at build-time the contents of each script will essentially be inserted into the main SQL file.)

Upvotes: 6

Related Questions