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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Check if a table is empty

Check if a table is empty

Scheduled Pinned Locked Moved Database
databasequestion
5 Posts 3 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.
  • O Offline
    O Offline
    ONeil Tomlinson
    wrote on last edited by
    #1

    Whats the best sql Statement to check if a table is empty? Thanks ONeil

    A 1 Reply Last reply
    0
    • O ONeil Tomlinson

      Whats the best sql Statement to check if a table is empty? Thanks ONeil

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

      select top 1 from ... is one way. Select count(*) from is another - could be slow though if the re are a lot of records.

      Bob Ashfield Consultants Ltd

      S 1 Reply Last reply
      0
      • A Ashfield

        select top 1 from ... is one way. Select count(*) from is another - could be slow though if the re are a lot of records.

        Bob Ashfield Consultants Ltd

        S Offline
        S Offline
        SomeGuyThatIsMe
        wrote on last edited by
        #3

        In sql server 2k i've actually seen Count(*) return a 1 when counting an empty table, had it happen several times, cant remember why it happened anymore.

        Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

        A 1 Reply Last reply
        0
        • S SomeGuyThatIsMe

          In sql server 2k i've actually seen Count(*) return a 1 when counting an empty table, had it happen several times, cant remember why it happened anymore.

          Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

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

          Never seen it myself, must have been fixed in an early service pack - after all, count is one of the fundamental functions.

          Bob Ashfield Consultants Ltd

          S 1 Reply Last reply
          0
          • A Ashfield

            Never seen it myself, must have been fixed in an early service pack - after all, count is one of the fundamental functions.

            Bob Ashfield Consultants Ltd

            S Offline
            S Offline
            SomeGuyThatIsMe
            wrote on last edited by
            #5

            I saw it happen in SP4, wish i could remmeber how and why it showed up.

            Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

            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