Search code examples
mysqlunique

Is there a way to make an entire MySQL row unique


I have a table in MySQL with 30 columns and thousands of entries.
Is there a way I could make every row unique, that means if a row already exists, I should not be able to enter that row again.

I can't use primary or unique keys here, because individually every column might be repeated.
I want the row to be unique. for example:-There are is a table with

columns->name,age,height,weight.

In this column I can't make any one or two columns unique but I should not have two entries with all the same data.


Solution

  • You need a composite primary key.

    A composite primary key tells MySQL that you want your primary key to be a combination of fields.

    More info here: Why use multiple columns as primary keys (composite primary key)