mysql combined unique keys

早过忘川 提交于 2019-11-30 08:51:48

You can define an index on multiple columns, e.g.:

CREATE UNIQUE INDEX arbitrary_index_name ON table_name (title, store);

Yes. Instead of two separate unique constraints you should create a single unique constraint on both columns.

The CREATE INDEX syntax is:

CREATE [UNIQUE|FULLTEXT|SPATIAL] INDEX index_name
    [index_type]
    ON tbl_name (index_col_name,...)
    [algorithm_option | lock_option] ...

For your example it would look something like this:

CREATE UNIQUE INDEX index_name ON tbl_name (title,store);

You will also have to drop the two incorrect unique indexes that you created.

See the documentation for more details on how to create indexes.

ALTER TABLE table_name ADD UNIQUE INDEX( title, store);

Yes you can!

ALTER TABLE table_name DROP PRIMARY KEY;
ALTER TABLE table_name ADD PRIMARY KEY(title, store);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!