Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. how to count number of records in table

how to count number of records in table

Scheduled Pinned Locked Moved Database
tutorial
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chithra r
    wrote on last edited by
    #1

    hi all can anyone tell me how to count the number of records(rows)in a table without using "COUNT" aggregate function. thanx in advance.

    pintoo

    J P G C 4 Replies Last reply
    0
    • C chithra r

      hi all can anyone tell me how to count the number of records(rows)in a table without using "COUNT" aggregate function. thanx in advance.

      pintoo

      J Offline
      J Offline
      Joe 2
      wrote on last edited by
      #2

      chithra.r wrote:

      without using "COUNT"

      What is that you are trying to do? If you are writing a proc, you may use @@RowCount[^] Pl: Read through the documentation listed in the above URL, to know the scenarios where it can be applied.

      Give a man a fish, he'll eat for a day. Teach a man how to fish, he'll eat for lifetime. Pradeep Joe

      A 1 Reply Last reply
      0
      • J Joe 2

        chithra.r wrote:

        without using "COUNT"

        What is that you are trying to do? If you are writing a proc, you may use @@RowCount[^] Pl: Read through the documentation listed in the above URL, to know the scenarios where it can be applied.

        Give a man a fish, he'll eat for a day. Teach a man how to fish, he'll eat for lifetime. Pradeep Joe

        A Offline
        A Offline
        Ashfield
        wrote on last edited by
        #3

        @@Rowcount is only gives you the number of rows affected by the last query, for example select count(*) from table1 will give an @@RowCount of 1 The best way I know of without using select count(*) is EXEC sp_spaceused 'tablename' which gives you name rows reserved data index_size unused If you only want an approximate count select max(rows) from sysindexes where indid < 2 and id = object_id('TableName') (this is not 100% accurate as rows sysindexes is not always updated)

        Bob Ashfield Consultants Ltd

        1 Reply Last reply
        0
        • C chithra r

          hi all can anyone tell me how to count the number of records(rows)in a table without using "COUNT" aggregate function. thanx in advance.

          pintoo

          P Offline
          P Offline
          Paddy Boyd
          wrote on last edited by
          #4

          What's wrong with COUNT()?

          1 Reply Last reply
          0
          • C chithra r

            hi all can anyone tell me how to count the number of records(rows)in a table without using "COUNT" aggregate function. thanx in advance.

            pintoo

            G Offline
            G Offline
            GuyThiebaut
            wrote on last edited by
            #5

            I wonder if you are misunderstanding what you can do with COUNT Try this query and see if the results it gives you are what you want:

            select 'Rows in table:'+cast((select count(*) from tablename)as varchar(20))
            
            You always pass failure on the way to success.
            1 Reply Last reply
            0
            • C chithra r

              hi all can anyone tell me how to count the number of records(rows)in a table without using "COUNT" aggregate function. thanx in advance.

              pintoo

              C Offline
              C Offline
              Chris Meech
              wrote on last edited by
              #6

              This might work instead

              Select MAX(rowid)-MIN(rowid) from table

              Chris Meech I am Canadian. [heard in a local bar] Donate to help Conquer Cancer[^]

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups