Unique key with multiple MySQL columns

I am familiar with the syntax create unique index 'blah' on 'some_table' ('col1','col2') however I do not know exactly how it will look. More specifically, the documentation says

A list of form columns (col1, col2, ...) creates an index with multiple columns. Index values ​​are formed by concatenating the values ​​of these columns.

It seems that in some cases this may be good, but I want to create a table containing only numbers that are unique. Thus, I could see that col1 is 12, and col2 is 2, which will be concatenated with 122 of what I can say, and then the value of col1 1 and col2 22 will correspond to what I do not want. Is there a way to define a separator for concatenation or is there already one in its place? Should I do it differently?

Here's a try on the chart

table 1             middle               table 2
-------             ------               -------
t1_id               mid_id               t2_id
some_value          t1_id                another_value
                    t2_id

, t1_id t2_id , t1 , t2 .

+3
1

. , .

+3

Source: https://habr.com/ru/post/1793666/


All Articles