constraints - Mysql Create Index Set As No Duplicates -
i have table p_places has 2 columns both foriegn keys references parent tables:
mysql> create table p_places( -> user_id int not null, -> place_id int not null, -> foreign key(user_id) references people(user_id) on delete cascade, -> foreign key(place_id) references places(place_id) on delete cascade -> )engine=innodb;
i trying create index both of columns there can not duplicate rows(there can duplicate foriegn keys however...just not rows).
i tried:
alter table p_places add index(user_id+place_id no duplicate); alter table p_places add unique index(user_id+place_id); alter table p_places add unique index both_id(user_id+place_id);
but had no success. try alter table command learning purposes rather creating table.
you close want.
alter table p_places add constraint tb_unique unique(user_id, place_id)
Comments
Post a Comment