Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL (Custom) Unique Constraint for a set of rows

How to create a ( may be custom) unique constraint for a particular no.of rows.

I have table data as below

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I want my itemFK column to be Unique for same productionsessionKey value. i.e for all yellow (101) itemFK should be Unique and for all blue (102) itemFK should be unique. Else they can be duplicate.

>Solution :

Add a unique constraint on a tupple for those 2 columns

F.e.

ALTER TABLE your_table
  ADD CONSTRAINT UC_Your_Table_ProdSession_Item UNIQUE (productionsessionKey, itemFK);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading