add primary keys to a table one-time and there are already

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lucas Gump

    add primary keys to a table one-time and there are already

    Is it possible to add primary keys to a table one-time and there are
    already
    multiple primary key defined?

    I have to change sp_id, so_id as primary keys to the existing primary
    keys
    dn_slot_id and dn_mm_id.

    I tried several times but all failed:
    1. alter table debit_slot_deta il add primary key (sp_id, so_id);
    2. alter table debit_slot_deta il add primary key (dn_slot_id, dn_mm_id,

    sp_id, so_id);

    thanks in advance for any help

  • Bill Karwin

    #2
    Re: add primary keys to a table one-time and there are already

    Lucas Gump wrote:[color=blue]
    > Is it possible to add primary keys to a table one-time and there are
    > already
    > multiple primary key defined?[/color]

    A table can have only one primary key (it counts as one if that key is a
    "compound key" comprised of multiple columns in the table). To add a
    new primary key, or change the columns that comprise the key, you have
    to drop the old one first. There is another usage of ALTER TABLE for this.

    Regards,
    Bill K.

    Comment

    Working...