Alternate answer with results:
let MissingTable = view () { print isMissing=1 };
union isfuzzy=true MissingTable, (AzureDiagnostics | getschema | summarize c=count() | project isMissing=iff(c > 0, 0, 1))
| top 1 by isMissing asc
This query returns a 1 if the AzureDiagnostics table doesn't exist in the cluster. If the real table doesn't exist, the fake row of the MissingTable will be returned. If any columns exist in the schema for the AzureDiagnostics table, a 0 is returned.
if you don't care if the table doesn't exist and just want 0 rows, instead of going through getschema
, you could just make the view have the columns you would have gotten in your query but just have no rows in that view/datatable:
let MissingTable = datatable(ResourceId: string) [];
union isfuzzy=true MissingTable, (AzureDiagnostics
| extend ResourceId = column_ifexists('ResourceId', '')
In this case, the query returns no rows if the AzureDiagnostics table is missing, or if the ResourceId column is missing from the table.
depending on where you are you might get a query warning indicator that tables were missing, that's expected behavior with fuzzy unions.
(also at https://learn.microsoft.com/en-us/azure/azure-monitor/visualize/workbooks-create-workbook#best-practices-for-querying-logs)