Created
January 23, 2024 21:16
-
-
Save jmyeary/5a03e9f6f35b1f868c6e9ae01f6ce7a0 to your computer and use it in GitHub Desktop.
synapse cursor to check multiple tables
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 @TableName nvarchar(128); | |
DECLARE @Command nvarchar(500); | |
DECLARE TableCursor CURSOR FOR | |
SELECT table_name FROM information_schema.tables | |
WHERE table_schema = 'myschema'; | |
OPEN TableCursor; | |
FETCH NEXT FROM TableCursor INTO @TableName; | |
WHILE @@FETCH_STATUS = 0 | |
BEGIN | |
-- Replace this with your command. For example, to select all rows from each table: | |
SET @Command = 'SELECT * FROM myschema.' + QUOTENAME(@TableName) + ';'; | |
EXEC sp_executesql @Command; | |
FETCH NEXT FROM TableCursor INTO @TableName; | |
END; | |
CLOSE TableCursor; | |
DEALLOCATE TableCursor; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment