1

不支持-

DELETE TOP(10000) FROM dataArchival.MyTable 
    WHERE DateLocal BETWEEN '2018-03-01' AND '2018-10-01'

delete dataArchival.MyTable
from dataArchival.MyTable d,#myTemp d2
where d.DateLocal=d2.DateLocal

delete d from dataArchival.MyTable d
(
 SELECT
        *,
        RN = ROW_NUMBER() OVER(ORDER BY (SELECT NULL))
    FROM dataArchival.MyTable
    where DateLocal  BETWEEN '2018-03-01' AND '2018-10-01'
)A where A.RN <=10000

并且也不支持ofcource CTE 和@@rowcount。

4

1 回答 1

0

根据文档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

于 2019-03-11T12:27:49.300 回答