simple query

  • how to get the count of rows in a table...urgent

  • SELECT COUNT(*) FROM TABLE

    Pradeep Adiga
    Blog: sqldbadiaries.com
    Twitter: @pradeepadiga

  • refer the COUNT function

    http://msdn.microsoft.com/en-us/library/ms175997.aspx

    ---------------------------------------------------
    "Thare are only 10 types of people in the world:
    Those who understand binary, and those who don't."

  • thanks

  • Even you can go with any column which are having distinct values.

    select count(column name) from table name.

  • ... or find all rows in all tables - code borrowed from many sources inc. James DBA!

    use MyDatabase

    SELECT o.name AS [TableName], i.rowcnt AS [RowCount]

    -- into master..tblDBHrows_20090522 -- this will allow saving the result

    FROM sysobjects o, sysindexes i

    WHERE i.id = o.id

    AND indid IN (0,1)

    --This specifies 'user' databases only

    AND xtype = 'u' --Added by James_DBA

    --This omits the diagrams table of the database

    --You may find other system tables will need to be ommitted,

    --you would just name them all here using the operator

    --i.e. o.name dtproperties, o.name 'sysdiagrams'

    AND o.name 'sysdiagrams' --Added by James-DBA

    --You could also look further into filtering out temp tables,

    --or user specified tables

    ORDER BY o.Name -- or by size as you prefer

  • shanila_minnu (5/20/2009)


    how to get the count of rows in a table...urgent

    Interview? 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply