chaneg primary key

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
lizlazloz
Forum Commoner
Posts: 64
Joined: Mon Dec 29, 2003 7:29 am

chaneg primary key

Post by lizlazloz »

hey, noob here, what is the mysql code to change the priamry key of a table?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

First, are you sure you want to change a primary key? If you've got several related tables this will break your program.

Check out the [mysql_man]mysql manual[/mysql_man] for info on column types and how to change them.

phpMyAdmin is a popular db tool.
fractalvibes
Forum Contributor
Posts: 335
Joined: Thu Sep 26, 2002 6:14 pm
Location: Waco, Texas

Post by fractalvibes »

Yep, as McGruff said. If this is a brand new table you might be better off just re-creating the table and drop the old. Some RDBMS are really particular on what they allow you to alter, esp. primary key or any columns with indices on them.

fv
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Code: Select all

alter table 'table' drop primary key, add primary key 'field'
Post Reply