471,090 Members | 1,287 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,090 software developers and data experts.

Primary key

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

Fred
Jul 19 '05 #1
2 7143
"Fred Blair" <fb*****@ev1.net> wrote in message news:<vo************@corp.supernews.com>...
How can I create a primary key after the table has been created?

Fred


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_specification [,
alter_specification ...]

alter_specification:
ADD [COLUMN] create_definition [FIRST | AFTER column_name ]
| ADD [COLUMN] (create_definition, create_definition,...)
| 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_definition]
| ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT}
| CHANGE [COLUMN] old_col_name create_definition
[FIRST | AFTER column_name]
| MODIFY [COLUMN] create_definition [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.
Jul 19 '05 #2
"Fred Blair" <fb*****@ev1.net> wrote in message news:<vo************@corp.supernews.com>...
How can I create a primary key after the table has been created?

Fred


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_specification [,
alter_specification ...]

alter_specification:
ADD [COLUMN] create_definition [FIRST | AFTER column_name ]
| ADD [COLUMN] (create_definition, create_definition,...)
| 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_definition]
| ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT}
| CHANGE [COLUMN] old_col_name create_definition
[FIRST | AFTER column_name]
| MODIFY [COLUMN] create_definition [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.
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by John Simmons | last post: by
5 posts views Thread by Ghulam Farid | last post: by
9 posts views Thread by 101 | last post: by
18 posts views Thread by Thomas A. Anderson | last post: by
4 posts views Thread by Peter | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.