0

今天我注意到当我更改视图中的表时,如果不运行 sp_refreshview,则不会更新该视图的 syscolumns。下面的代码显示了我在说什么

create table Test ( n1 decimal(12,4) )
go
create view VTest as Select * from Test;
go
sp_help VTest
go
alter table Test alter column n1 decimal(12,2)
go
sp_help VTest

请注意,VTest 保持静态,是否有某种方法可以自动执行此过程?

4

1 回答 1

4

您需要调用sp_refreshview以更新视图

create table Test ( n1 decimal(12,4) )
go
create view VTest as Select * from Test;
go
sp_help VTest
go
alter table Test alter column n1 decimal(12,2)
EXEC sp_refreshview  VTest
go
sp_help VTest
于 2013-05-08T14:30:14.750 回答