开发者

How can I include an ALTER VIEW statement in a transaction for a deploy script?

开发者 https://www.devze.com 2022-12-14 04:26 出处:网络
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

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?


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
0

精彩评论

暂无评论...
验证码 换一张
取 消