This script is handy when you want to list all views on an instance or even find a specific view if you know the name but don’t know the database.
— Written by John McCormack
— This script uses the unspported stored procedure sp_msforeachdb so there are more reliable ways of going about this task.
— It uses a table variable and inserts each row returned into the table variable
— The ? is the database – All databases will be
DECLARE @views table (DBName sysname, ViewName nvarchar(100))
INSERT INTO @views
SELECT ”?”,name FROM sys.views
— where [name] = ”vw_CurrentDaySales”’
— Uncomment the where clause if you wanted to find a specific view
SELECT * FROM @views
Leave a Reply