Number of records in the table

Source: Internet
Author: User

 

Self-written declare @ count int
Declare @ sqlstring nvarchar (500)
, @ Tablename varchar (100)
Select top 1 @ tablename = Name from sysobjects where xtype = 'U'
Select @ sqlstring = 'select @ innercount = count (1) from' + @ tablename

Execute sp_executesql
@ Sqlstring
, N' @ innercount int output'
, @ Innercount = @ count output
Select @ tablename + 'number of records: '+ Cast (@ count as varchar (20): declare @ name varchar (200)
Declare @ I int
Declare @ result table (name varchar (100 ))
Declare @ s nvarchar (100)
Declare a cursor for (Select name from sysobjects where type = 'U') open
Fetch next from a into @ name
While @ fetch_status = 0
Begin
Set @ s = 'select top 10 @ I = count (1) from '+ @ name +''
Exec sp_executesql @ s, n' @ I int output', @ I
Output
If @ I> 0
Insert into @ result select @ name
Fetch next from a into @ name
End
Close
Deallocate
Select * From @ result

 

 

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.