1

I've done a little research on this in the past hour, and I could use some help understanding some things.

Why doesn't this work? Got the basis for it from link

ALTER TABLE customers
MODIFY COLUMN customer_id INT AUTO_INCREMENT PRIMARY KEY;

When I attempt to run it, I receive the error: Multiple primary key defined.

It works when I take out PRIMARY KEY, but is it still doing what I need it to do? (which is increment the customer_id, which is a PK, by 1.)

The customer_id is a primary key, does marking it as a primary key make it think that there are two?

Another question, when you use AUTO_INCREMENT without declaring how many it increments by, what is the default value to increment, 1?

Community
  • 1
  • 1
Sierra
  • 327
  • 4
  • 11
  • I assume you mean to say that `customer_id` was already the primary key before this `MODIFY`? If so, yes, your auto increment will be working correctly. If you look at `SHOW CREATE TABLE customers`, you should see both the PK and auto_increment in `customer_id`. – Michael Berkowski Apr 11 '16 at 16:29
  • 1
    MySQL will not permit adding auto_increment on a column which is not a primary key. – Michael Berkowski Apr 11 '16 at 16:30
  • You probably has one or more primary keys in this table. You can certainly add more then 1 primary keys to the table, but you should do it at once. Drop any pk first, the try again. Autoincrement value is 1. – kolodi Apr 11 '16 at 16:31
  • Thank you very much. Just needed some clarification on that. :) Thanks for telling me how to check as well! (@MichaelBerkowski) – Sierra Apr 11 '16 at 16:31
  • @misher Well, the only primary key I have is customer_id...not sure what else could be causing it to not work based on your response. I don't even have a foreign key for that one. Thank you for answering auto_increment question though! :) – Sierra Apr 11 '16 at 16:33

0 Answers0