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
Solved

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

Posted on 2000-03-28
2
719 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
2 Comments
 
LVL 11

Accepted Solution

by:
mikeblas earned 75 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Complete beginner needs help making a cron job 9 125
Smart Camera scanning and reading information 3 114
Detect file exist or not 3 180
x-bar in Google Sheets 2 71
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…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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 an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

829 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