查询所有表中的记录数

create function row_count
(@tablename  varchar(200))
returns table
as return(
   with row_count(name,count)as
  ( select name,sum(rows) count
   from sys.partitions p
   left join sys.allocation_units a ON p.partition_id = a.container_id
   ,sysobjects  c
   where
   p.object_id =  c.id
   and p.index_id in(0,1)
   and p.rows is not null
   and a.type = 1
   and c.type = 'U'
   group by name )
select * from row_count  where name = (case @tablename when '*' then  name else @tablename  end )
)

你可能感兴趣的:(C++,c,C#)