/ Published in: SQL
This lite fiuntion is a simple organizator rowcount for all datatables for one single database.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
DECLARE @id AS NUMERIC DECLARE @name AS NVARCHAR (MAX) DECLARE @xtype AS CHAR DECLARE @crdate AS DATETIME DECLARE @sqlint AS NUMERIC DECLARE @paramDefinition AS NVARCHAR (MAX) DECLARE @paramValue AS NVARCHAR (MAX) CREATE TABLE ##specsAndModel (tablename NVARCHAR (MAX), VALUE NUMERIC) DECLARE tblCursor CURSOR FOR SELECT id, name, xtype, crdate FROM sys.sysobjects WHERE xtype = N'U' OPEN tblCursor FETCH NEXT FROM tblCursor INTO @id, @name, @xtype, @crdate WHILE @@FETCH_STATUS = 0 BEGIN DECLARE @SQL AS NVARCHAR (MAX) SET @SQL = 'insert into ##specsAndModel SELECT @tablename , count(1) FROM ' + @name SET @paramDefinition = '@tablename nvarchar(max)' SET @paramValue = @name EXEC sp_executesql @SQL, @paramDefinition, @paramValue FETCH NEXT FROM tblCursor INTO @id, @name, @xtype, @crdate END CLOSE tblCursor DEALLOCATE tblCursor SELECT tablename, VALUE FROM ##specsAndModel GROUP BY tablename, VALUE HAVING VALUE > 0 ORDER BY VALUE DESC DROP TABLE ##specsAndModel