Last active
July 13, 2023 11:11
-
-
Save pipin68k/f3a06c0271da9365257ba487ec02b44c to your computer and use it in GitHub Desktop.
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
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