Avacay
Avacay

Reputation: 163

Composite primary key mySQL

Im doing a project in the school, where i ran into an issue with my composite primary keys..

when im defining my composite primary keys, i type in the following:

ALTER TABLE `Product Shipment` DROP PRIMARY KEY, ADD PRIMARY KEY(Product_code,Shipment_ID)

mySQL is returning with following error:

#1832 - Cannot change column 'Shipment_ID': used in a foreign key constraint 'Shipment_ID'

Im then trying to remove my following key by:

alter table `product Shipment` drop constraint `Shipment_ID`

Where im getting a random error,

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'constraint Shipment_ID' at line 1

Im pretty new to this, and dont seem to get how i will do this the right way.. :s

Help is much appreciated!

Upvotes: 0

Views: 338

Answers (1)

Abhik Chakraborty
Abhik Chakraborty

Reputation: 44844

For dropping the foreign key constraint you can use the following

ALTER TABLE `product Shipment` DROP FOREIGN KEY `Shipment_ID`;

Upvotes: 1

Related Questions