mysql - add new column to existing Composite Unique Key -


i have table named "room" , , has following composite unique key

room_acid_levelid_year_name_unique 

formed 4 columns :

acid levelid year name 

and want add column islevel key without drop , recreate it

the new key should this:

room_acid_levelid_year_name_islevel_unique 

with following columns :

acid levelid year name islevel 

note want alter key , not drop , create again . 2 columns acid , levelid foreign keys.

thanks

finally solved problem following steps:

  1. show index keys table room

    show create table room; 
  2. i have drop foreign keys acid , levelid

    alter table room drop foreign key room_acid_foreign; alter table room drop foreign key room_levelid_foreign; 

    (remember use key names got on query in step one)

  3. now can drop unique key room_acid_levelid_year_name_unique

    alter table room drop index room_acid_levelid_year_name_unique; 
  4. add again 2 foreign keys again

    alter table  room add foreign key (sacid) references sac(id) on update cascade on delete restrict;  alter table  room add foreign key (levelid) references level(id) on update cascade on delete restrict; 
  5. add new key of 5 columns

    alter table room add unique key  room_acid_levelid_year_name_islevel_unique  (acid, levelid, year, name, islevel); 

i hope else.


Comments