I'm changing my mysql db table from an id (auto) to a uid.
ALTER TABLE companies DROP PRIMARY KEY; ALTER TABLE companies ADD PRIMARY KEY (`uuid`);
This is the error I get..
[SQL] ALTER TABLE companies DROP PRIMARY KEY; [Err] 1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key
Which I understand, I need to change the id to a non-autoincrement because I drop it as the primary key.? What is the syntax to change a column to remove primary key and auto increment?
ALTER TABLE companies change id id ?????????? int(11)
You don't want to drop the column but moving forwarding you don't need to have auto increment, instead you would like to insert the values in column manually. To disable or remove the auto increment from a column in MySQL Table, you can simply Modify the column with same data type but without auto_increment clause.
Auto-increment allows a unique number to be generated automatically when a new record is inserted into a table. Often this is the primary key field that we would like to be created automatically every time a new record is inserted.
You can drop a primary key in MySQL using the ALTER TABLE statement.
If you need to remove the auto-increment and the primary key from the id
column in a single SQL statement, this should do:
ALTER TABLE companies DROP PRIMARY KEY, CHANGE id id int(11);
In fact, you should be able to do everything in a single ALTER TABLE
query:
ALTER TABLE companies DROP PRIMARY KEY, CHANGE id id int(11), ADD PRIMARY KEY (uuid);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With