Solved

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

Posted on 2000-03-28
2
712 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
Comment Utility
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
Comment Utility
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 Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now