...but may come in handy for some
You da real MVP.
I got a phone call form a junior dev at midnight. He was deploying an update where a column was changed from int to varchar. The views using that column were still returning int and the application was was failing. When I realized that recompiling a view would fix the problem, I didn't know what views to fix and your script was the third result from my frantic search.
The one feature I'd like to see is some way to not stop on an error. Is that possible without over complication? I encountered three views that would not recompile and I had to fix them before I could finish running the script.
After your WHERE clause, I added
ORDER BY name so I could see how far it went before failing. My three erroneous views were all in a row.
Thank you for sharing this snippet! 😛