我的约束脚本出错=“有”

时间:2016-03-08 22:54:43

标签: sql-server

CONSTRAINT [PK_SLD] PRIMARY KEY CLUSTERED 
([SLD_ID] ASC )
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,  
      IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY], 
 CONSTRAINT [USLD_NKEY] UNIQUE NONCLUSTERED 
 (
    [P_TYP] ASC 
    WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, 
          IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, 
          ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
    ) ON [PRIMARY]
 GO 

我正在尝试在SQL中编写约束,我收到以下错误:

  

第15行,第1行,第1行,第1行   关键字“CONSTRAINT”附近的语法不正确。

     

Msg 319,Level 15,State 1,Line 7
  关键字'with'附近的语法不正确。如果此语句是公用表表达式,xmlnamespaces子句或更改跟踪上下文子句,则必须以分号结束前一个语句。

有什么明显的东西我做错了吗?

1 个答案:

答案 0 :(得分:1)

看起来你没有指定一个表来添加这个约束,你在第二个约束的列名之后缺少一个结束')',我不确定你的第三个'On [Primary]'在哪里正在使用。

ALTER TABLE your_table
ADD CONSTRAINT [PK_SLD] PRIMARY KEY CLUSTERED 
([SLD_ID] ASC )
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY], 
 CONSTRAINT [USLD_NKEY] UNIQUE NONCLUSTERED 
 (
    [P_TYP] ASC 
   ) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]

 GO