Manickus Manickus - 11 months ago 60
MySQL Question

Unique value in field for specific field in sql

I have to create a new table in

, but I have a problem.

I want to have a unique value in one field but only for a specific field in same table, similar like a one to many.


And now I want to have ID_Order unique for the table, and ID_Supplier_Order only for specific Supplier. Can I do it in one table, or I have to create a second for Suppliers?

Answer Source

Taken from:

Add unique constraint to combination of two columns

CREATE UNIQUE INDEX uq_yourtablename
  ON dbo.yourtablename(column1, column2);