根据文档Azure SQL 数据仓库目前不TOP(n)
支持DELETE
:
-- Syntax for Azure SQL Data Warehouse and Parallel Data Warehouse
DELETE FROM [database_name . [ schema ] . | schema. ] table_name
[ WHERE <search_condition> ]
[ OPTION ( <query_options> [ ,...n ] ) ]
[; ]
但是,您可以编写类似效果的脚本,例如,此示例改编自此示例以按日期删除:
CREATE TABLE #tmp
WITH (
DISTRIBUTION = ROUND_ROBIN
)
AS
SELECT
ROW_NUMBER() OVER( ORDER BY ( SELECT NULL ) ) AS rowId,
DateLocal
FROM ( SELECT DISTINCT DateLocal FROM dataArchival.MyTable ) x;
DECLARE @sql_code NVARCHAR(4000) = 'DELETE dataArchival.MyTable WHERE DateLocal = @p1'
DECLARE @nbr_statements INT = ( SELECT COUNT(*) FROM #tmp ),
@i INT = 1;
WHILE @i <= @nbr_statements
BEGIN
DECLARE @p1 DATE = ( SELECT DateLocal FROM #tmp WHERE rowId = @i );
EXEC sp_executesql @sql_code, N'@p1 DATE', @p1
SET @i +=1;
END
如果按日期删除不满意,您可以轻松更改此示例以批量删除 10,000 个。这里还有一个批量删除的附加示例:
https://docs.microsoft.com/en-us/azure/sql-data-warehouse/sql-data-warehouse-develop-best-practices-transactions#minimize-logging-with-small-batches