Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6896513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:03:11+00:00 2026-05-27T07:03:11+00:00

Is there a standard way to check if a table exists in a database

  • 0

Is there a standard way to check if a table exists in a database using only pure SQL and nothing that is database specific? Basically an equivalent of IF EXISTS that will work when used on any datasource (SQL compliant of course).

UPDATE

How can I make the examples given work in this statement?

IF(SELECT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'clusterTable200m' 
AND TABLE_TYPE='BASE TABLE')) 
BEGIN  
SELECT 'Exists' 
END 
ELSE  
BEGIN  CREATE TABLE clusterTable200m(CLUSTER_ID int NOT NULL, CELL_GEOM   geometry NOT NULL, CELL_CENTROID geometry NOT NULL , CLUSTER_CENTROID   geometry , CLUSTER_EXTENT  geometry , NUM_POINTS  int , FEATURE_PK  int , PRIMARY KEY (CLUSTER_ID)) SELECT 'Complete'  
END

UPDATE

The above code is a minds eye of how I want the SQL to work but it has been pointed out that I cannot have the IF without a stored procedure or similar and this is out of the question. I also cannot reference for example sysobjects from ms sql server as this is specific to that data source.

I know it is a tricky one but if anyone can offer a solution it would be greatly appreciated.

UPDATE

Ok so as it stands the only work around I have thought of is as follows:

        string sqlQuery = "SELECT * FROM " + tableName;

        OleDataBaseConnection oleDataBaseConnection = new OleDataBaseConnection();

        bool tableExists = true;

        try
        {
            oleDataBaseConnection.OleExecutePureSqlQuery(sqlQuery);
        }
        catch (Exception exc)
        {
            if (exc.Message.ToUpper().Contains("EXIST"))
            {
                tableExists = false;
            }
            else
            {
                throw;
            }
        }

This code will attempt to return all items from the table(will be changed to just attempt a return of the first record to prevent performance impact) and if it fails it checks the error message for the word exists (so as not to supress other exceptions) If the word exists is present I assume that the table is not in the database. Then further down my code if the table does not exist then I run the pure SQL to create the new table. This is the only work around I have though of so far and I welcome any input.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:03:12+00:00Added an answer on May 27, 2026 at 7:03 am

    Using INFORMATION_SCHEMA, for those systems that comply:

    SELECT EXISTS
           ( SELECT *
             FROM INFORMATION_SCHEMA.TABLES
             WHERE TABLE_CATALOG = 'CatalogName'
               AND TABLE_SCHEMA = 'SchemaName' 
               AND TABLE_NAME = 'TableName'
           ) AS answer
    FROM dual              --- this may be required in some systems.
    

    Information_schema docs:

    • SQL-Server

    • PostgreSQL

    • MySQL

    • DB2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a standard way to check if a view layout exists from within
There is a table in our database that acts very much like a standard
Is there a standard way to simulate a table creation in a database by
Is there some standard way or has anyone written something that allows you to
Is there a standard way to bind arrays (of scalars) in a SQL query?
Is there a standard way to check whether the sound recording is possible in
Is there standard way to implement standard Iphone Check List like when you choose
Is there a standard way to check whether construction of a new std::codecvt_byname succeeded?
Of course I realize that there's no one right way to design a SQL
Is there a standard way to convert an XSD to an input form (ASP.NET

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.