Skip to content

Instantly share code, notes, and snippets.

@jmyeary
Created January 23, 2024 21:16
Show Gist options
  • Save jmyeary/5a03e9f6f35b1f868c6e9ae01f6ce7a0 to your computer and use it in GitHub Desktop.
Save jmyeary/5a03e9f6f35b1f868c6e9ae01f6ce7a0 to your computer and use it in GitHub Desktop.
synapse cursor to check multiple tables
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