I have a Product
table in my DB with following columns:
ProductId INT IDENTITY PRIMARY KEY
ProductCode VARCHAR(100) NOT NULL
ProductStamp VARCHAR(100) NOT NULL
ProductId is primary key. I need both ProductCode and ProductStamp unique separately (not combined). For example:
Allowed
Code Stamp
... ---- -----
A001 S001
A002 S002
Not allowed
Code Stamp
... ---- -----
A001 S001
A001 S002
How do I achieve this?
2条答案
按热度按时间v64noz0r1#
Unique constraint on a single column:
These will raise an error if there are two rows with duplicate product codes, OR product stamps.
Unique constraint on a multiple columns:
This will fire if there are two rows with code AND stamp the same.
The convention "AK" for naming stands for "Alternate Key"
zour9fqk2#
You need to add a Unique Index: