2

One of our tables is loosing a column and related views need to be refreshed. I ran the procedure sp_refreshview ok on it's own for one view, although I had to pick the actual database, even though I had the DB.dbo.View_name extension.

I am now wanting to run a few of these update view statements in one script that does the table update too, but keep getting this error message saying incorrect syntax near sp_refreshview. I have tried putting go after the statement to contain it, with the USE [DB_Name] statement before each update. Like below:

use [DB1]
sp_refreshview 'DB1.dbo.View1'
go

use [DB2]
sp_refreshview 'DB2.dbo.View1'
go

It keep failing for some reason. Granted this is the first time I have set a batch script to update multiple views in different DBs so if there is a better way to do this I am open to suggestions.

MSDN.WhiteKnight
  • 664
  • 7
  • 30
Andrew
  • 1,728
  • 8
  • 28
  • 39

1 Answers1

2

To fix your syntax error, I believe all you are missing is an "EXEC" before your sp_refreshview's:

USE [DB1]
EXEC sp_refreshview 'DB1.dbo.View1'
GO

USE [DB2]
EXEC sp_refreshview 'DB2.dbo.View1'
GO
Ben Bloodworth
  • 900
  • 11
  • 26