1

I want to change the column name of a table.

That column name is (ID) and that is primary key and auto_increment column.

I found the query to change the column name is

Alter table mytable change ID, AppID INT(11);

But its throwing error, Because of the primary key. So i am trying to drop the primary key, But not able to drop primary key also.

How can i drop the primary key which has auto_increment in the same column.

Thanks.

Aashick
  • 91
  • 2
  • 15

4 Answers4

2

the first line will remove autoincrement, second one will remove key

ALTER TABLE mytable MODIFY id INT NOT NULL;
ALTER TABLE mytable DROP PRIMARY KEY;

you probably want to add the key back later using

ALTER TABLE mytable ADD PRIMARY KEY(id)
1

First drop the auto increment property and then drop the primary key.
Refer - Remove Primary Key in MySQL

Community
  • 1
  • 1
Narendra Jaggi
  • 1,297
  • 11
  • 33
0

Aashrick, you won't be able to drop primary key ... But, you could try a work around, and do something like drop your current table, and create it again, with the changes you would like.

drop table mytable;
create table mytable ... etc
Eugen
  • 785
  • 6
  • 22
0

I'm not sure how to link to specific answers, but I wanted to point you to this topic which helped me out in a similar situation:

Updating MySQL primary key The answer by franzras (at the bottom on my end) was the one that helped me out.

He says one needs to remove the auto-increment first, then we can drop and re-add the primary key as normal.

Community
  • 1
  • 1
Annihlator
  • 204
  • 1
  • 2
  • 12