2005-11-10

MS SQL Server

Here is an MS SQL query that writes an SQL query to show the row counts for all user tables:

select line
from (
  select 0 seq, 'select null table_name, null row_count where 1=2' line
  union select 1, 'union select '''+name+''', count(*) from ['+name+']'
    from dbo.sysobjects where type='U' and name<>'dtproperties'
  union select 2, 'order by 1'
) lines
order by seq, line