在更改主键时,我收到此错误

时间:2018-02-21 08:16:04

标签: sql-server sql-server-2008 tsql ddl

ALTER TABLE VASTHRA_TALLY_BRIDGE.DBO.[VF_TALLY_MIGRATION_VOUCHER_DETAILS_GST_19_20] 
WITH NOCHECK ADD CONSTRAINT
VASTHRA_TALLY_BRIDGE.DBO.[VF_TALLY_MIGRATION_VOUCHER_DETAILS_GST_19_20] 
PRIMARY KEY  CLUSTERED  
( 
    voucher_Number,
    voucher_date,
    Debit Account Head,
    Credit Account Head,
    ITEM_NAME,
    RATE
)  ON [PRIMARY] END
  

Msg 102,Level 15,State 1,Line 1语法不正确'。'。

2 个答案:

答案 0 :(得分:5)

约束名称不需要DB也不需要这里的模式规范。

必须引用带空格的列。

ALTER TABLE VASTHRA_TALLY_BRIDGE.DBO.[VF_TALLY_MIGRATION_VOUCHER_DETAILS_GST_19_20] WITH NOCHECK ADD CONSTRAINT
 [VF_TALLY_MIGRATION_VOUCHER_DETAILS_GST_19_20] PRIMARY KEY  CLUSTERED  
 ( voucher_Number,voucher_date,
   [Debit Account Head],[Credit Account Head],ITEM_NAME,RATE)  
ON [PRIMARY]

END关键字在此处非法,因为未指定BEGIN

答案 1 :(得分:1)

您正在命名约束VASTHRA_TALLY_BRIDGE.DBO.[VF_TALLY_MIGRATION_VOUCHER_DETAILS_GST_19_20]。一个对象,也是一个约束,不允许在其名称中包含点。因此,您应该为其指定一个不同的名称,例如PK_VF_TALLY_MIGRATION_VOUCHER_DETAILS_GST_19_20