Created
January 4, 2011 22:04
-
-
Save jboeke/765530 to your computer and use it in GitHub Desktop.
Test All SQL Views
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
ALTER PROCEDURE [dbo].[spTestAllViews] | |
AS | |
BEGIN | |
-- SET NOCOUNT ON added to prevent extra result sets from | |
-- interfering with SELECT statements. | |
SET NOCOUNT ON; | |
DECLARE @Loopid int, @MaxID int, @ViewName varchar(100) | |
SELECT quotename(table_schema) +'.' + quotename(table_name) as ViewName, identity(int,1,1) as ID | |
INTO #test | |
FROM information_schema.tables | |
WHERE table_type = 'view' | |
SELECT @LoopID =1,@MaxID =MAX(id) | |
FROM #test | |
WHILE @LoopID <= @MaxID | |
BEGIN | |
SELECT @ViewName = ViewNAme | |
FROM #test | |
WHERE id = @LoopID | |
EXEC ('SELECT TOP 1 * FROM ' + @ViewName) | |
SET @LoopID = @LoopID + 1 | |
END | |
DROP TABLE #test | |
END | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment