Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I got a piece of code to check the existence of a table from . This is applicable for [^]. The revised code for OleDB is below:
C#
public bool CheckTableExist(OleDbConnection conn, string tblName)
{
    bool b = false;
    string[] restrictions = new string[]  { null, null, tblName };
    DataTable dTable = conn.GetSchema("Tables", restrictions);
    if (dTable.Rows.Count == 0)
    {
        b = false;
    }
    else
    {
        b = true;
    }
    return b;
}


This may also be applicable for SQL Server, or any other OLE database, but is NOT for Oracle DB. How to check the existence of a table in Oracle DB? Thanks in advance if you can share your experience.
Posted
Comments
[no name] 18-Sep-13 11:13am    
http://www.bing.com/search?q=How+to+check+the+existence+of+a+table+in+Oracle+DB

1 solution

You can usually find this in Oracle by checking the user_tables object.

Something like this should do it:

SQL
SELECT COUNT(table_name) FROM user_tables WHERE table_name='tlbNameToCheckFor'
 
Share this answer
 
Comments
[no name] 18-Sep-13 15:00pm    
Dear hypermellow:
Thanks for your post. I test this sql statement in Oracle SQL Developer. It works fine.
hypermellow 19-Sep-13 3:56am    
I'm glad it helped!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900