Search code examples
sql-server-2008visual-studio-2012sql-server-data-tools

Do I need to code TRANSACTIONs for multiple SQL operations in my post-deployment scripts?


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.


Solution

  • 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).