Is possible to add a primary key in a table that already have a unique nonclustered index?
I have a table cargo_car and i need to define cd_cargo_car as a PK.
I tried this:
ALTER TABLE dbo.cargo_car ADD PRIMARY KEY (cd_cargo_car)
but i received the error:
Error (1921) An index with the same columns inthe same order alredy exists onthe table
This table has many dependences and when i try to drop the index I receive:
Error (3712) Cannot drop index 'cargo_car.XPKcargo_car' because it still has referential integrity constraints.
This is the Create script:
CREATE TABLE dbo.cargo_car
(
cd_cargo_car SMALLINT NOT NULL,
nm_cargo_car VARCHAR (40) NOT NULL,
cd_refini_car CHAR (4) NOT NULL,
cd_reffin_car CHAR (4) NOT NULL,
cd_jornada1_car CHAR (2) NOT NULL,
cd_jornada2_car CHAR (2) NOT NULL
)
GO
CREATE UNIQUE NONCLUSTERED INDEX XPKcargo_car
ON dbo.cargo_car (cd_cargo_car)
GO
Suggestion on how to do this?
Tks
To allow closing this question, I converted that comment to an answer. It is correct and similar to what I wanted to write…