Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8908889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:17:53+00:00 2026-06-15T03:17:53+00:00

Is possible to add a primary key in a table that already have a

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:17:54+00:00Added an answer on June 15, 2026 at 3:17 am

    you’re going to have to drop all the foreign key contraints on the
    other tables, drop that index, create the Primary Key (I guess you
    want it to be clustered?), then re-create the foreign key constraints.
    – Dems

    To allow closing this question, I converted that comment to an answer. It is correct and similar to what I wanted to write…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table called t1 with a PRIMARY KEY that I will call
I have this table in an Oracle DB which has a primary key defined
Is it possible to add cluster to an existing table? For example... I have
Let's imagine I have an table called Foo with a primary key FooID and
I have a simple table with a primary key. Most of the read operations
I have a table named Groups with primary key = Pkey . In Group
Is it possible to add a table view on the cells of a table
Is it possible to add to PHP objects on the fly? Say I have
Is it possible to add sprite feature in XTK ? I need to render
Is it possible to add a form to an email newsletter? I have tried

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.