composite-key

How do I specify unique constraint for multiple columns in MySQL?

一世执手 提交于 2019-11-25 21:43:50
问题 I have a table: table votes ( id, user, email, address, primary key(id), ); Now I want to make the columns user, email, address unique (together). How do I do this in MySql? Of course the example is just... an example. So please don\'t worry about the semantics. 回答1: ALTER TABLE `votes` ADD UNIQUE `unique_index`(`user`, `email`, `address`); 回答2: I have a MySQL table: CREATE TABLE `content_html` ( `id` int(11) NOT NULL AUTO_INCREMENT, `id_box_elements` int(11) DEFAULT NULL, `id_router` int(11)