I used the SQL Server management studio to generate script against Azure Data Warehouse. I selected Edition Azure Data Warehouse, it generates below the script to drop table if it exists and create table. However, the script cannot pass validation. Please see below for the error message.
DROP TABLE IF EXISTS Table1
GO
Error message:
Parse error at line: 2, column: 12: Incorrect syntax near 'IF'.
The DROP TABLE statement deletes the specified table, and any data associated with it, from the database. The IF EXISTS clause allows the statement to succeed even if the specified tables does not exist. If the table does not exist and you do not include the IF EXISTS clause, the statement will return an error.
To drop a table from within the current database (on-premises or Azure SQL Database) we simply pass the name of the table in the form [schema_name]. [table_name]. As before, we get an error that shows us the table is no longer there trying when we try to select from it.
The reason SQL won't let you drop a table in this situation is because the allocation pages/extent chain appears to be damaged or cross-linked in some way. So SQL Server thinks that there is actually data from other tables in pages/extents belonging to the problem object.
As indicated in the documentation, DROP TABLE IF EXISTS
is not currently supported in Azure SQL Data Warehouse, as at today:
-- Syntax for SQL Server and Azure SQL Database
DROP TABLE [ IF EXISTS ] [ database_name . [ schema_name ] . | schema_name . ]
table_name [ ,...n ]
[ ; ]
-- Syntax for Azure SQL Data Warehouse and Parallel Data Warehouse
DROP TABLE [ database_name . [ schema_name ] . | schema_name . ] table_name
[;]
Bob's answer is correct. I tried to add the following as a comment, but it looked terrible without formatting.
You can use the following syntax as an alternative:
if object_id ('dw.dim_location','U') is not null drop table dw.dim_location;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With