Last active
December 18, 2015 02:49
-
-
Save DylanKnevitt/5714090 to your computer and use it in GitHub Desktop.
A basic loop to select all columns from all tables/views in a database, useful with the Database Engine Tuning Advisor on SSMS for a very basic idea of what indices and statistics are missing.
This file contains 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
DECLARE TOCURSOR CURSOR FOR | |
SELECT('SELECT * FROM [' + name + '];') | |
FROM sys.tables | |
--FROM sys.views | |
ORDER BY name ASC | |
DECLARE @query NVARCHAR(MAX) | |
OPEN TOCURSOR | |
FETCH NEXT FROM TOCURSOR INTO | |
@query | |
WHILE @@FETCH_STATUS = 0 | |
BEGIN | |
EXEC (@query) | |
FETCH NEXT FROM TOCURSOR INTO | |
@query | |
END | |
CLOSE TOCURSOR | |
DEALLOCATE TOCURSOR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment