0
votes

I'm using

  • SQL Server 2008 (not R2)
  • Visual Studio 2012 Premium
  • SQL Server Database Project/SQL Server Data Tools (SSDT)

Do I need to use TRANSACTIONs when I have multiple SQL statements (CREATE, UPDATE, DELETE) in my post-deployment scripts? When I look at our deployment script generated by SSDT, from what I can tell, SSDT only uses transactions for SQL that it generates based on the diff script.

2

2 Answers

2
votes

If you want all operations to be rolled back if any of them fail, wrap all operations in a single transaction. Otherwise, if any of them encounter a failure that operation will stop and any previous changes will remain. Otherwise you can just end each operation with a semicolon for clarity, though SQL Server doesn't require it (yet).

1
votes

You are correct that the transaction created by SSDT only wraps the diff part of the deployment and not the pre and post scripts.

Whether or not this is an "issue" depends on what you are doing in the post deploy.

If your post-deployment scripts are

  1. Tested
  2. Idempotent

this shouldn't cause you too many problems.