Creating a table only if it does not exist using ANSI sql

I am trying to dynamically create an SQL table only if it no longer exists. I have seen many solutions on the Internet, but they usually rely on a specific database, while I try to find the most general solution.

I thought that I always run the CREATE command, and then I assume that if it failed, then there is a table, and I can start inserting data into it. I see no flaws in this reasoning (apart from performance issues), but I could be wrong.

Is this an acceptable method?

Can you suggest other methods that are database independent or that use ANSI SQL that will accept all RDBMSs?

+3
source share
3

INFORMATION_SCHEMA ANSI SQL, :

IF NOT EXISTS(SELECT NULL FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'YourTable')
    CREATE TABLE...
+1

- - EMP, , EMP, ?

, ...

0

and what:

create table if not exists
-1
source

All Articles