I have several tables with primary keys. I did not give these primary keys constraints any name. Is it possible to give them name now and how? I am using MySQL 5.7.
Asked
Active
Viewed 2,727 times
0
-
3Possible duplicate of http://stackoverflow.com/q/1463363/2037090 – Irvin Lim Jun 20 '16 at 17:09
-
Not index, primary key. – ruslan5t Jun 20 '16 at 17:12
-
2The name of a PRIMARY KEY is always PRIMARY, which thus cannot be used as the name for any other kind of index. – Ranjeet Singh Jun 20 '16 at 18:01
1 Answers
0
Try this
ALTER TABLE `mytable`
DROP PRIMARY KEY,
CHANGE COLUMN oldname newname INT(11) DEFAULT NULL,
ADD CONSTRAINT `mytable_newname_pk` PRIMARY KEY (`newname`)

Syed Haris Ali Ghaznavi
- 745
- 1
- 12
- 32