How to include an ALTER VIEW statement in a transaction to deploy a script?

I am running SQL Server 2005 on prod, but developing in 2008, and I need to change the view to add a column. However, I am unable to create the deployment script because I need to wrap it in a transaction like this

begin tran; alter view [dbo].[v_ViewName] with schemabinding as select ... /* do other stuff */ commit; 

When I do this, the SQL IDE underlines the alter statement with an error, stating that the ALTER VIEW statement should be the only statement in the package. ANd, if I ignore this and just try to run it anyway, it gives this error:

Invalid syntax next to the keyword 'view'.

Any ideas how to get around this?

+4
source share
1 answer

A transaction can span multiple batches:

 begin tran; GO alter view [dbo].[v_ViewName] with schemabinding as select ... GO /* do other stuff */ GO commit; GO 
+10
source

All Articles