简体   繁体   中英

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

在此处输入图像描述

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

Add a unique constraint on a tupple for those 2 columns

Fe

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM