Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Portable SQL to determine if a table exists or not?

Is there a portable way of determining if a database table already exists or not?

like image 553
jkp Avatar asked Aug 04 '09 14:08

jkp


People also ask

How do you check SQL table exists or not?

Using the OBJECT_ID and the IF ELSE statement to check whether a table exists or not. Alternative 2 : Using the INFORMATION_SCHEMA. TABLES and SQL EXISTS Operator to check whether a table exists or not.

How can you tell if a table is present in a database?

If the user is SYSTEM or has access to dba_tables data dictionary view, then use the given below query: Query: SELECT owner, table_name FROM dba_tables; This query returns the following list of tables that contain all the tables that are there in the entire database.

How do you check if a table exists in a schema?

How to check whether a table (or view) exists, and the current user has access to it? SELECT EXISTS ( SELECT FROM information_schema. tables WHERE table_schema = 'schema_name' AND table_name = 'table_name' ); The information schema is mainly useful to stay portable across major versions and across different RDBMS.


1 Answers

Portable? I don't think so.

Maybe the closest you can get is:

select * from <table>

And this would return an error if the table doesn't exist.

like image 81
Alan Avatar answered Oct 26 '22 14:10

Alan