Adding a Primary Key to a MySQL Table
When attempting to add a primary key to an existing MySQL table using the command:
alter table goods add column `id` int(10) unsigned primary AUTO_INCREMENT;
one might encounter an error. To resolve this, it is necessary to add the PRIMARY KEY keyword explicitly:
alter table goods add column `id` int(10) unsigned PRIMARY KEY AUTO_INCREMENT;
Alternatively, you can add the primary key after adding the column:
ALTER TABLE goods ADD PRIMARY KEY(id)
This ensures that the id column becomes the primary key for the table. By explicitly specifying PRIMARY KEY, you can avoid the confusion that might arise from using the word PRIMARY alone.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3