Error 'View/Table Does Not Exist' during model or query runtime in SQL Analytics

Use the command ALTER VIEW to update the view definition.

Written by wanderson.oliveira

Last published at: January 10th, 2025

Problem

When working with SQL Analytics you encounter an error during runtime in your model or query indicating that a view or table does not exist, even after it has been created. 

[TABLE_OR_VIEW_NOT_FOUND] The table or view <your-catalog>.<your-database>.<your-table> cannot be found.

 

Cause

You’re executing a job that uses CREATE OR REPLACE on an underlying view while running another job concurrently that attempts to read the same view. 

Replacing a view is a delete-and-recreate operation, which means the view's old information, (including table_id and credentials) is not retained. If a query attempts to access the view while it is being replaced, the credentials will no longer be valid, leading to the view/table does not exist error.

 

Solution

Databricks recommends using the ALTER VIEW command to update the view definition instead of CREATE OR REPLACE VIEW.  This approach preserves the table_id and ensures that the view remains accessible during updates.

 

Example

ALTER VIEW <your-catalog>.<your-database>.<your-view> AS
SELECT * FROM <your-catalog>.<your-database>.<your-table>;

 

For further guidance, refer to the ALTER VIEW (AWSAzureGCP) documentation.