Skip to content

Instantly share code, notes, and snippets.

@jboeke
Created January 4, 2011 22:04
Show Gist options
  • Save jboeke/765530 to your computer and use it in GitHub Desktop.
Save jboeke/765530 to your computer and use it in GitHub Desktop.
Test All SQL Views
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