Manickus Manickus - 3 months ago 9
MySQL Question

Unique value in field for specific field in sql

I have to create a new table in

SQL
, 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.

Table:
ID_Order
Supplier
ID_Supplier_Order


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

Taken from:

Add unique constraint to combination of two columns

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