Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rename a primary key column

Status
Not open for further replies.

clarissa1996

Technical User
Jan 31, 2002
78
CH
Hi all,

I have the table t1 with the column A.
The column A is defined as:
INT NOT NULL PRIMARY KEY AUTO_INCREMENT.

I need to rename A -> B but the following command report an error:

ALTER TABLE t1 CHANGE A B INT NOT NULL PRIMARY KEY AUTO_INCREMENT

ERROR 1068: Multiple primary key defined

Any help is appreciated.

Clarissa
 
if B can contain null values than it cannot be the primary key.

I have also found that you will need to remove any foreign keys that column A links to before you can drop column A as the primary key and change it to column B.

You will also need to remove the primary key from column A before making column B a primary key.

Jason Meckley
Database Analyst
WITF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top