0
votes

What SQL query can I use to check if a table exists.

I need to support different versions of schema, and some deployments can miss certain tables

1
Are the tables in cache Or externally connected via jdbc/odbc? - mccrackend

1 Answers

1
votes

If they are Cache tables, you may use the %Dictionary.CompiledClass system table.

select id from %Dictionary.CompiledClass where SqlSchemaName='%BI' and SqlTableName='Alerts'

Or, if you know Cache class name of your table,

select id from %Dictionary.CompiledClass where ID='%BI.Alerts'

These queries will return 1 row if table %BI.Alerts exists.