I have the following table schema which maps user_customers to permissions on a live MySQL database:
mysql> describe user_customer_permission;
+------------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| user_customer_id | int(11) | NO | PRI | NULL | |
| permission_id | int(11) | NO | PRI | NULL | |
+------------------+---------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
I would like to remove the primary keys for user_customer_id and permission_id and retain the primary key for id.
When I run the command:
alter table user_customer_permission drop primary key;
I get the following error:
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key
How can I drop a column's primary key?
INSERT IGNORE
, to remove a mapping,DELETE
the row matching both FKs. This way, you cannot have duplicates because the primary key enforces correctness. Bonus points if you have proper foreign key relations set up that cascade updates and deletes from the parent tables. – Tantalus