当我尝试在表中创建复合主键时发生错误?

时间:2015-03-26 18:03:13

标签: sql sql-server

ALTER TABLE WorkOrder
    ADD CONSTRAINT Wo_system PRIMARY KEY (WorkOrderNumber,AssetCode)

当我尝试执行上述查询时,发生以下错误:

Msg 1779, Level 16, State 0, Line 1
Table 'WorkOrder' already has a primary key defined on it.
Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.

我删除了主键WorkOrderNumber,但仍然会产生相同的错误。

有人能为我解决这个问题吗?

2 个答案:

答案 0 :(得分:2)

ALTER TABLE WorkOrder
    DROP CONSTRAINT pk_wrkord 
GO
ALTER TABLE WorkOrder
      ADD CONSTRAINT Wo_system PRIMARY KEY (WorkOrderNumber,AssetCode)
GO

答案 1 :(得分:0)

你可能没有放下钥匙:

尝试

exec sp_pkeys 'workorder'