Answer the question
In order to leave comments, you need to log in
How to create a table with 2 keys?
There is a table with columns id, name, house
In the id column there are duplicate id because in the house column these ids belong to different objects for example
id, name, house
value
15,blabla, house1
15,blabla, house2
16,blabla, house3
16,blabla , house4
16, blabla, house5
there is no unique column on which to update the data and assign a key
Is it possible to somehow assign this key to two columns? so that the check for duplicates goes in the id and house columns?
Or how can the problem be solved?
Dividing into 2 tables is not an option
Answer the question
In order to leave comments, you need to log in
Didn't quite get the gist of the question, but yes: you can create a composite unique index (id, house ). If you create it, then the table can only have one entry "15, blabla, house1".
Firstly, it is not clear why there are duplicates in the table, and even on the id column.
De facto in all projects that I have seen, if this field is present, it is unique (at least autoincement).
Secondly, a similar question is easily searched by a search engine. For example here .
If you want to know more, google "mysql composite primary key"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question