Store procedure row count

  • maharaj.narayanan

    SSC Veteran

    Points: 230

    hi,

    Needed a small help

    select table_name,count(*) into #temp from information.schema.table

    which will return the table name and their corresponding row count.

    i need this in a store procedure where this information should be inserted into a temp table.

    thankyou.

  • Jeff Moden

    SSC Guru

    Points: 993645

    maharaj.narayanan (5/24/2014)


    hi,

    Needed a small help

    select table_name,count(*) into #temp from information.schema.table

    which will return the table name and their corresponding row count.

    i need this in a store procedure where this information should be inserted into a temp table.

    thankyou.

    Other than the fact that you don't have the required GROUP BY on that code, what's stopping you from using it in a stored procedure?

    If that's ALL that the stored procedure is going to consist of, I wouldn't bother because it's useless then. The Temp Table won't be available outside the stored proc and you really don't want to use a Global Temp Table because that will cause concurrency problems.

    --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.
    "If you think its expensive to hire a professional to do the job, wait until you hire an amateur."--Red Adair
    "Change is inevitable... change for the better is not."
    When you put the right degree of spin on it, the number 3|8 is also a glyph that describes the nature of a DBAs job. 😉

    Helpful Links:
    How to post code problems

Viewing 2 posts - 1 through 2 (of 2 total)

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