简体   繁体   English

在 Azure 突触 SQL 脚本上显示语法错误

[英]Showing error in syntax on Azure synapse SQL script

My code is我的代码是

SET ANSI_NULLS ON 
GO
SET QUOTED_IDENTIFIER ON 
GO

CREATE TABLE [dbo].[RLS_LOGS] 
WITH (
    DISTRIBUTION = ROUND_ROBIN,
    CLUSTERED COLUMNSTORE INDEX
     )
    AS
    (
    [USER_IDENTITY] [nvarchar](4000) NOT NULL,
    [DESCRIPTION] [nvarchar](4000) NOT NULL,
    [CREATED_ON] [datetime2](7) NOT NULL DEFAULT (GETDATE())
    )

Showing the error while running SQL script on azure synapse (Dedicated server pool)在 azure 突触(专用服务器池)上运行 SQL 脚本时显示错误

You have some of the clauses a bit out of order.你的一些条款有点乱。 This should work:这应该工作:

CREATE TABLE [dbo].[RLS_LOGS] 
    (
    [USER_IDENTITY] [nvarchar](4000) NOT NULL,
    [DESCRIPTION] [nvarchar](4000) NOT NULL,
    [CREATED_ON] [datetime2](7) NOT NULL
    )
WITH (
    DISTRIBUTION = ROUND_ROBIN,
    CLUSTERED COLUMNSTORE INDEX
     )

I had to remove the getdate() default because as documented here :我不得不删除 getdate() 默认值,因为如此记录:

In Azure Synapse Analytics, only constants can be used for a default constraint.在 Azure Synapse Analytics 中,默认约束只能使用常量。 An expression cannot be used with a default constraint.表达式不能与默认约束一起使用。

You will just have to ensure each INSERT statement inserts getdate() to that column.您只需确保每个 INSERT 语句都将 getdate() 插入该列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM