Saturday, 26 November 2011

How to Find Number of Record in All Table in SQL SERVER


DECLARE @name VARCHAR(500)
DECLARE @sql VARCHAR(1000)

CREATE TABLE #TableRecordCount
( TableName VARCHAR(100),
  RecordCount INT
)

DECLARE dbCursor CURSOR FAST_FORWARD
FOR SELECT T.NAME FROM SYSOBJECTS T WHERE T.XTYPE = 'U' AND LEFT(T.NAME,1)<>'_' AND NOT T.NAME='Timeline' ORDER BY T.NAME

OPEN dbCursor
FETCH NEXT FROM dbCursor INTO @name
WHILE @@FETCH_STATUS = 0
BEGIN
      SET @sql = 'INSERT INTO #TableRecordCount (TableName, RecordCount) '
      SET @sql = @sql + 'SELECT ''' + @Name + ''' AS TableName, COUNT(*) AS CNT '
      SET @sql = @sql + 'FROM [' + @name + ']'
      EXEC (@sql)
      FETCH NEXT FROM dbCursor INTO @name
END

CLOSE dbCursor
DEALLOCATE dbCursor

SELECT SUM(RecordCount) FROM #TableRecordCount
SELECT * FROM #TableRecordCount WHERE RecordCount>50 ORDER BY RecordCount DESC

DROP TABLE #TableRecordCount

3 comments:

  1. Unbelievable Offer about Make your own Website
    (Example: www.yourcompanyname.com)
    Full Website Design & Hosting is Free of Cost for our 10th year Celebration .

    Facilities:
    1. Full Dynamic Site
    2. 5 Pages site
    3. Google Map enable
    4. Custom Domain name choice (Like- .com, .org, .in, .co.in, .asia etc)
    5. Unlimited bandwidth
    6. Quick Contact form


    Terms & Condition:
    1. You need to buy Domain name by self or from us. If you buy domain name from us, cost will be INR 499/- only
    2. Your website will be valid for one year. After that you can renew your website.
    3. Website must be for your organization / company name. This offer not valid for any person name.
    4. Clients will no choice for website colour or any custom design.
    5. Client will not get Server ID & Password.
    6. For any problem client need to send email : support@technosysgroup.in


    Contact Details :

    Mobile : 9830710980

    e-mail : info@technosysgroup.in

    Website : www.technosysgroup.in

    ReplyDelete
  2. Need facebook "Like" for your facebook page ?


    We providing 1000 likes for USD $20 only
    Limited preiod offer.

    Contact ID
    ------------------
    Skype : raju.alam
    -------------------------
    e-mail : mybusinessking@gmail.com

    Skypee : mybusinessking |raju.alam

    Website : http://www.businessking.asia

    Get Free Facebook Like


    Computer Tips & Tricks, Movie Downlaod, e-book, SEO, Hacking Tips, free software, health tips


    COMPLETE WEBSITE JUST INR 1499/-


    SHOP ONLINE IN KOLKATA ONLY


    NORTH 24 PARGANAS, WEST BENGAL, INDIA


    Job In West Bengal, India


    low cost domain name

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete