Sample Header Ad - 728x90

How can I run sp_refreshview across all views in my SQL Server database

3 votes
2 answers
896 views
I'm using SQL Server, and I received an error indicating that one or more of my SQL views is out of sync with its underlying SQL table. > 'MySQLServerName' returned data that does not match expected data > length for column 'MyColumnName'. The (maximum) expected data length > is 50, while the returned data length is 52. This occurs if you update the definition of the underlying SQL table, but forget to update the associated SQL view(s). A quick fix for this error is to run sp_refreshview : use MySQLDatabaseName go EXECUTE sp_refreshview N'MyViewName'; **But what if I have a long list of broken views, or I don't even know which views are broken, or I don't know which underlying table definitions are no longer matching those views? What if I want to save time by running sp_refreshview across every view in my database. What's an easy way to accomplish that task?**
Asked by Speedcat (349 rep)
Oct 22, 2024, 02:29 AM
Last activity: Oct 24, 2024, 02:30 AM