Skip to content

Instantly share code, notes, and snippets.

@pipin68k
Last active July 13, 2023 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pipin68k/f3a06c0271da9365257ba487ec02b44c to your computer and use it in GitHub Desktop.
Save pipin68k/f3a06c0271da9365257ba487ec02b44c to your computer and use it in GitHub Desktop.
DROP TABLE IF EXISTS #temp_tablelist
CREATE TABLE #temp_tablelist(
[table_name] [nvarchar](50) NOT NULL,
[rec] integer NOT NULL
)
DECLARE table_cursor CURSOR FOR
SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'
DECLARE @table_name AS NVARCHAR(50)
OPEN table_cursor
FETCH NEXT FROM table_cursor INTO @table_name
WHILE @@FETCH_STATUS = 0
BEGIN
EXECUTE ('insert into #temp_tablelist select ''' + @table_name + ''' ,count(*) from ' + @table_name)
FETCH NEXT FROM table_cursor INTO @table_name
END
CLOSE table_cursor
DEALLOCATE table_cursor
select * from #temp_tablelist order by table_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment