How do you use SQL to see if a table exists or not?

Possible duplicate:
SQL Server: check if the

Oracle table exists: if the table exists

I am trying to create a table and insert some values, but before I do this, I have to make sure that the table does not exist yet. How do you do this?

+3
source share
5 answers

You can simply select SELECT from it and capture the error, otherwise you will need to write a specific SQL SQL to query their respective metadata tables and look there.

+1
source

IF MySQL:

select count(*) from my_tables where table_name='table_1'; 
If count>0 then  ...
0
source

SQL Server... Query sysobjects:

select * from sysobjects where xtype='U' and name ='tablename'
0

MySQL CREATE TABLE IF NOT EXISTS INSERT. , , .

CREATE TABLE IF NOT EXISTS myTable (
    ....
)

http://dev.mysql.com/doc/refman/5.1/en/create-table.html

http://docs.oracle.com/cd/E17952_01/refman-5.1-en/create-table.html

0
source

This simple query gives you detailed information about a specific table created by users in oracle. Give it a try.

 select * from user_tables where table_name = 'tablename';
0
source

All Articles