Overview
When databases are created or upgraded, data may need to be added, changed, or deleted. Moreover, certain actions may have to occur on the database before and/or after the process completes. Pre and Post Deployment scripts can be used to accomplish this.Explanation
In our SSDT SQL project, we've defined a new table but we need a way to insert inital seed data into it. This can be accomplished by creating a PostDeploy script. In the Solution Explorer, right click on the Futbol project and choose Add->Script.Choose Post-Deployment Script and click Add.
When a database publish occurs, 3 blocks of code are created within a central .sql script which is generated by Visual Studio. This final auto generated script is what is ultimately deployed to the database. This script has three main blocks of code produced in this order:
- All code that makes up Scripts.PreDeployment.sql
- Auto generated code representing database schema creates/drops/changes based on the contents of the project
- All code that makes up Scripts.PostDeployment.sql
You may be wondering how a pre deployment script could be useful. One situation to consider is a complex migration of data. Using the pre and post deployment scripts, you could perform some up front work prior to deployment occurring and then work on that data after the deployment occurs.
source collected from mssqltips.com
No comments :
Post a Comment