2016-03-08 65 views
0
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約束,我發現了以下錯誤:錯誤在我的約束腳本=「與」

Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'CONSTRAINT'.

Msg 319, Level 15, State 1, Line 7
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.

有什麼明顯的,我做錯誤?

回答

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 
+0

感謝您的回覆,上面有一個更大的創建表格腳本。我沒有在原始問題中加入。 – webdad3

+0

那麼它與你的第二次衝突。列名後沒有關閉')'。更新的代碼。你是否需要[主要]'語句3'? – dfundako

+0

謝謝,這是問題。 – webdad3