Create table tmp (name varchar (500), rows int, reserved varchar (500 ),
Data varchar (500), index_size varchar (500), unused varchar (500 ))
Insert into tmp (name, rows, reserved,
Data, index_size, unused) exec sp_msforeachTable @ Command1 = "sp_spaceused '? '"-- Sp_spaceused 't_ vehicle'
Select * from tmp order by [rows] desc
Drop table tmp
Or I can write it myself, but only the number of rows does not use the system stored procedure 1 declare @ maxrowcount int
2 declare @ maxtablename varchar (200)
3 declare @ SQL nvarchar (2000)
4 declare @ tempcount int
5 set @ SQL = '';
6 set @ maxtablename = '';
7 create table # rowcount
8 (counts int, tname varchar (200 ))
9 declare Tnamecursor cursor for select name from sysobjects where xtype = 'U' and OBJECTPROPERTY (id, N 'isusertable') = 1
10 declare @ name varchar (200 );
11 open Tnamecursor
12 fetch next from Tnamecursor INTO @ name
13 WHILE @ FETCH_STATUS = 0
14 BEGIN
15 set @ SQL = 'select @ tempcount = count (*) from '+ @ name + 'insert into # rowcount values (@ tempcount, @ name )';
16 print @ SQL
17 exec sp_executesql @ SQL, n' @ tempcount int, @ name varchar (200) ', @ tempcount, @ name
18 -- print @ name + 'total count: '+ Convert (varchar (200), @ tempcount)
19 if (@ maxrowcount <@ tempcount)
20 begin
21 set @ maxrowcount = @ tempcount;
22 set @ maxtablename = @ name;
23 end
24 fetch next from Tnamecursor INTO @ name
25 end
26 CLOSE Tnamecursor
27 DEALLOCATE Tnamecursor
28
29 select * from # rowcount order by counts desc
30
31 drop table # rowcount
32
33
34
35
36
37