anugrah s p
anugrah s p

Reputation: 17

When I tried to create a composite primary key in a table an error is occurring?

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

When i tried to execute the query above the following error is occurring :

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.

I had deleted the primary key WorkOrderNumber but its still creating the same error.

Can some one give me a solution for this?

Upvotes: 0

Views: 2040

Answers (2)

Rubens Farias
Rubens Farias

Reputation: 57946

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

Upvotes: 2

benjamin moskovits
benjamin moskovits

Reputation: 5458

You probably did not drop the key:

Try

exec sp_pkeys 'workorder'

Upvotes: 0

Related Questions