Primary key

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fred Blair

    #1

    Primary key

    How can I create a primary key after the table has been created?

    Fred


  • Kevin Holmes

    #2
    Re: Primary key

    "Fred Blair" <fblair4@ev1.ne t> wrote in message news:<vocma5rvq qvhf7@corp.supe rnews.com>...[color=blue]
    > How can I create a primary key after the table has been created?
    >
    > Fred[/color]

    Fred,

    You need to use the ALTER TABLE command. You can find this in the
    MySQL reference manual. I have pasted the relevant section here for
    you.

    ALTER [IGNORE] TABLE tbl_name alter_specifica tion [,
    alter_specifica tion ...]

    alter_specifica tion:
    ADD [COLUMN] create_definiti on [FIRST | AFTER column_name ]
    | ADD [COLUMN] (create_definit ion, create_definiti on,...)
    | ADD INDEX [index_name] (index_col_name ,...)
    | ADD PRIMARY KEY (index_col_name ,...)
    | ADD UNIQUE [index_name] (index_col_name ,...)
    | ADD FULLTEXT [index_name] (index_col_name ,...)
    | ADD [CONSTRAINT symbol] FOREIGN KEY [index_name]
    (index_col_name ,...)
    [reference_defin ition]
    | ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT}
    | CHANGE [COLUMN] old_col_name create_definiti on
    [FIRST | AFTER column_name]
    | MODIFY [COLUMN] create_definiti on [FIRST | AFTER column_name]
    | DROP [COLUMN] col_name
    | DROP PRIMARY KEY
    | DROP INDEX index_name
    | DISABLE KEYS
    | ENABLE KEYS
    | RENAME [TO] new_tbl_name
    | ORDER BY col
    | table_options

    Regards,
    Kevin.

    Comment

    • Kevin Holmes

      #3
      Re: Primary key

      "Fred Blair" <fblair4@ev1.ne t> wrote in message news:<vocma5rvq qvhf7@corp.supe rnews.com>...[color=blue]
      > How can I create a primary key after the table has been created?
      >
      > Fred[/color]

      Fred,

      You need to use the ALTER TABLE command. You can find this in the
      MySQL reference manual. I have pasted the relevant section here for
      you.

      ALTER [IGNORE] TABLE tbl_name alter_specifica tion [,
      alter_specifica tion ...]

      alter_specifica tion:
      ADD [COLUMN] create_definiti on [FIRST | AFTER column_name ]
      | ADD [COLUMN] (create_definit ion, create_definiti on,...)
      | ADD INDEX [index_name] (index_col_name ,...)
      | ADD PRIMARY KEY (index_col_name ,...)
      | ADD UNIQUE [index_name] (index_col_name ,...)
      | ADD FULLTEXT [index_name] (index_col_name ,...)
      | ADD [CONSTRAINT symbol] FOREIGN KEY [index_name]
      (index_col_name ,...)
      [reference_defin ition]
      | ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT}
      | CHANGE [COLUMN] old_col_name create_definiti on
      [FIRST | AFTER column_name]
      | MODIFY [COLUMN] create_definiti on [FIRST | AFTER column_name]
      | DROP [COLUMN] col_name
      | DROP PRIMARY KEY
      | DROP INDEX index_name
      | DISABLE KEYS
      | ENABLE KEYS
      | RENAME [TO] new_tbl_name
      | ORDER BY col
      | table_options

      Regards,
      Kevin.

      Comment

      Working...