Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
lizlazloz
Forum Commoner
Posts: 64 Joined: Mon Dec 29, 2003 7:29 am
Post
by lizlazloz » Tue Dec 30, 2003 6:30 am
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 » Tue Dec 30, 2003 8:10 am
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 » Wed Dec 31, 2003 8:24 pm
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
JAM
DevNet Resident
Posts: 2101 Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:
Post
by JAM » Thu Jan 01, 2004 12:37 am
Code: Select all
alter table 'table' drop primary key, add primary key 'field'