Solved

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

Posted on 2000-03-28
2
717 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need a Shell script to start a service checking the port 6 50
Error on moodle after upgrade 3 131
iSeries FTP Exit Program 8 136
dog bark java program 15 97
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

803 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