Created
February 23, 2018 21:20
-
-
Save freemanirl/443fb54d38b21d1ee840b5ad56ed0826 to your computer and use it in GitHub Desktop.
Generate plan text for all dbs and views in a schema
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET NOCOUNT ON | |
GO | |
PRINT 'SET SHOWPLAN_TEXT ON' | |
PRINT 'GO' | |
DECLARE @query nvarchar(max) | |
DECLARE cur CURSOR FOR | |
SELECT 'SELECT * FROM [' + sys.schemas.name + '].[' + sys.objects.name + ']' AS [--stmt] | |
FROM sys.objects INNER JOIN | |
sys.schemas ON sys.objects.schema_id = sys.schemas.schema_id | |
WHERE (sys.objects.type = 'V') | |
OPEN cur | |
FETCH NEXT FROM cur INTO @query; | |
WHILE @@FETCH_STATUS = 0 | |
BEGIN | |
PRINT @query | |
FETCH NEXT FROM cur INTO @query; | |
END | |
CLOSE cur; | |
DEALLOCATE cur; | |
PRINT 'GO' | |
PRINT 'SET SHOWPLAN_TEXT OFF' | |
PRINT 'GO' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment