tags:

views:

45

answers:

1

I'm running SQL Server 2005 on prod, but developing on 2008, and I need to alter a view to add a column. However I'm having trouble creating the deploy 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 saying that the 'ALTER VIEW' statement must be the only statement in a batch. ANd if I ignore this and just try and run it anyway it gives this error:

Incorrect syntax near the keyword 'view'.

Any ideas how to get around this?

+4  A: 

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
Remus Rusanu