?
Solved

ODBC - how to check if table already exist, if not create table..

Posted on 2000-03-28
2
Medium Priority
?
728 Views
Last Modified: 2013-11-20
hi guys,

would like to know how to check if a table already exists in the database, and if not then I would like to create the table...

I am using VC6(MFC with ODBC Apis) and SQL Server 7.0...can anybody guide me with some sample code..?

Thanks!

0
Comment
Question by:Haho
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
mikeblas earned 225 total points
ID: 2666047
If you know the database you're talking to, then just use the system catalog. For instance, if you're using SQL Server, just check the SYSOBJECTS table for your table.

If you don't know the database, then try executing a meaningless query. Like:

   UPDATE YourTable
     SET YourTable.Column = YourTable.Colum
  WHERE 1 = 0

If the error you get back is about the table not being found, then you know the table doesn't exist.  If you get no error back, you know the table exists.

..B ekiM
0
 
LVL 3

Expert Comment

by:V_Bapat
ID: 2666136
Hi Haho
Use ::SqlTables() to get the list of all tables in the database.
For privileges for a table call ::SqlTablePrivileges()

Vicky
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question