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. Does Table Exist

Does Table Exist

Scheduled Pinned Locked Moved Database
databasehelpc++question
2 Posts 2 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.
  • E Offline
    E Offline
    Errol
    wrote on last edited by
    #1

    Environemnt: VC++6,Access DB via ODBC. How would one determine if a table exists in the database. I have tried "SELECT * FROM TABLE_NAME" where TABLE_NAME is the table I want to check for existence. Thinking I would get an error or invalid return, Yet the the error gets trap and an caught before I can get to it or test for a return condition? There has to be an easy way to check for table existance. RIGHT? Thanks for any help --Errol

    H 1 Reply Last reply
    0
    • E Errol

      Environemnt: VC++6,Access DB via ODBC. How would one determine if a table exists in the database. I have tried "SELECT * FROM TABLE_NAME" where TABLE_NAME is the table I want to check for existence. Thinking I would get an error or invalid return, Yet the the error gets trap and an caught before I can get to it or test for a return condition? There has to be an easy way to check for table existance. RIGHT? Thanks for any help --Errol

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Try this:

      IF EXISTS (SELECT name FROM sysobjecs WHERE id = object_id(N'tablename')
      AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
      SELECT * FROM tablename

      Or to get a list of tables (using this query in the EXISTS clause above also works), this is even easier:

      SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES

      "Well, I wouldn't say I've been missing it, Bob." - Peter Gibbons

      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