查询表占用空间大小

  • Post author:
  • Post category:其他



DECLARE


@sql

AS


NVARCHAR

(


300

),


@schmeaname

AS


sysname

,



@tablename

AS


sysname

;



DECLARE

C

CURSOR FAST_FORWARD FOR


SELECT

table_schema

,

table_name


FROM

INFORMATION_SCHEMA

.

tables


WHERE

table_type


=


‘BASE TABLE’


OPEN

C


FETCH NEXT FROM

C

INTO

@schmeaname

,

@tablename

;



WHILE

@@FETCH_STATUS


=

0


BEGIN



SET


@sql


=



N’EXEC sp_spaceused N”’



+


QUOTENAME

(

@schmeaname

)



+


N’.’



+


QUOTENAME

(

@tablename

)



+

N”’;’

;



EXEC

(

@sql

);


FETCH NEXT FROM

C

INTO

@schmeaname

,

@tablename

;



END


CLOSE

C

;



DEALLOCATE

C

;








spacer.gif

转载于:https://blog.51cto.com/charlist/1697478


关闭菜单