WITH 子句导致的 Azure SQL 服务器查询错误

Azure SQL Server Query error caused by WITH clause

以下 SQL 来自 Microsoft Azure 官方团队的 tutorial on Azure Synapse Analytics is giving the following error related to WITH clause in common table expression (CTE)

在 Azure 门户中查询:

CREATE TABLE [dbo].[Trip]
(
    [DateID] int NOT NULL,
    [MedallionID] int NOT NULL,
    [HackneyLicenseID] int NOT NULL,
    [PickupTimeID] int NOT NULL,
    [DropoffTimeID] int NOT NULL,
    [PickupGeographyID] int NULL,
    [DropoffGeographyID] int NULL,
    [PickupLatitude] float NULL,
    [PickupLongitude] float NULL,
    [PickupLatLong] varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [DropoffLatitude] float NULL,
    [DropoffLongitude] float NULL,
    [DropoffLatLong] varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [PassengerCount] int NULL,
    [TripDurationSeconds] int NULL,
    [TripDistanceMiles] float NULL,
    [PaymentType] varchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [FareAmount] money NULL,
    [SurchargeAmount] money NULL,
    [TaxAmount] money NULL,
    [TipAmount] money NULL,
    [TollsAmount] money NULL,
    [TotalAmount] money NULL
)
WITH
(
    DISTRIBUTION = ROUND_ROBIN,
    CLUSTERED COLUMNSTORE INDEX
);

COPY INTO [dbo].[Trip]
FROM 'https://nytaxiblob.blob.core.windows.net/2013/Trip2013/QID6392_20171107_05910_0.txt.gz'
WITH
(
    FILE_TYPE = 'CSV',
    FIELDTERMINATOR = '|',
    FIELDQUOTE = '',
    ROWTERMINATOR='0X0A',
    COMPRESSION = 'GZIP'
)
OPTION (LABEL = 'COPY : Load [dbo].[Trip] - Taxi dataset');

在我将 WITH 子句替换为 ;WITH:

之前出错

Failed to execute query. Error: Incorrect syntax near 'DISTRIBUTION'. Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.

但是在关注用户 @KMthis response 之后出现类似的错误,当我将 WITH 替换为 ;WITH 时,出现以下错误。 Azure Portal 中的错误没有显示错误的确切位置:

我将 WITH 子句替换为 ;WITH:

后出错

Failed to execute query. Error: Incorrect syntax near '('.

问题:Microsoft 教程的查询中可能缺少什么,我们如何解决错误?

备注:Azure Portal 中上述sql 的以下截图显示了一些红线,似乎表明上述sql 有一些语法错误.但与 SSMS 不同的是,Azure 门户中的智能感知不会显示这些语法错误的原因。也许,对上述查询有更好理解的人可能会有所帮助。

发现问题,当我没有更改池名称时遇到同样的错误。此命令在“SQL on-demand”中不起作用,因此我们应该将池更改为在本教程的第 1 步中创建的新池,然后它就会起作用。

我创建的名称是-test,在教程中是'SQLDB1'。 Select 这个并尝试 运行。

我会提高 PR 以在 MS 文档中添加此行。