Breaking News
Loading...
13/03/2013

Use sp_spaceused to get total records in tables

Please note that this returns total records of all tables belong to one database.
IF OBJECT_ID('tempdb..#tablesize') IS NOT NULL DROP TABLE #TableSize 
  CREATE TABLE #TableSize 
  ( Name       VARCHAR(512), 
  Rows       INT, 
  Reserved   VARCHAR(18), 
  Data       VARCHAR(18), 
  Index_size VARCHAR(18), 
  Unused     VARCHAR(18)) 

  insert into #TableSize exec sp_msforeachtable 'exec sp_spaceused ''?''' 
Muốn thống kê ở cấp độ database
EXECUTE master.sys.sp_MSforeachdb 'USE [?]; EXEC sp_spaceused'

0 comments:

Post a Comment

 
Toggle Footer