Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top