I have a table with structure
Table-a Id was primary开发者_Go百科 key
ID | Name
1 | Gourav
2 | Amit
3 | Rahul
But After that primary key automatically removed by restoring database to other database..
Now Records in Table are
ID | Name
1 | Gourav
2 | Amit
3 | Rahul
0 | AAA
0 | BBB
0 | CCC
How can i add primary key to id column again and can handle the existing data as well in MYSQL.
Thanks in advance..
Add PK as AUTO_INCREMENT, it will change all 0 values automatically -
ALTER TABLE table_a
CHANGE COLUMN id id INT(11) NOT NULL AUTO_INCREMENT,
ADD PRIMARY KEY (id);
After, AUTO_INCREMENT property can be removed -
ALTER TABLE table_a
CHANGE COLUMN id id INT(11) NOT NULL;
精彩评论