Gets the number of rows and other information for all tables in the database

Source: Internet
Author: User

if exists (SELECT * from tempdb. sysobjects where id=object_id (' tempdb. #Data '))
drop table #Data
CREATE TABLE #Data (name varchar), row varchar (+), reserved varchar (+), Data varchar (+), index_size varchar (100) , unused varchar (100))

DECLARE @name varchar (100)
DECLARE cur cursor FOR
Select name from sysobjects where xtype= ' u ' ORDER by name
Open cur
FETCH NEXT from cur to @name
While @ @fetch_status =0
Begin
INSERT INTO #data
EXEC sp_spaceused @name
Print @name

FETCH NEXT from cur to @name
End
Close cur
Deallocate cur
if exists (SELECT * from tempdb. sysobjects where id=object_id (' tempdb. #DataNew '))
drop table #DataNew
CREATE TABLE #DataNew (name varchar, row int,reserved int,data int,index_size int,unused int)

INSERT INTO #dataNew
Select Name,convert (Int,row) as Row,convert (Int,replace (reserved, ' KB ', ")) as Reserved,convert (int,replace (data, ' kb ', ') as data,
Convert (Int,replace (index_size, ' KB ', ')) as Index_size,convert (Int,replace (Unused, ' KB ', ")) as unused from #data
SELECT * from #dataNew ORDER BY row Desc

Gets the number of rows and other information for all tables in the database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.