3

I have a table that contain 3 columns:

ID int [primary key]

BranchRef int [foreign key]

Code int

I need to [Code] be unique in each [BranchRef]

like:

ID      BranchRef      Code
1           1            1
2           1            2
3           2            1
4           2            2
5           1            3

I really appreciate any help

Pouria Sharif
  • 156
  • 1
  • 15

1 Answers1

3

Add a unique constraint.

ALTER TABLE mytable ADD CONSTRAINT UNIQUE(BranchRef, Code);
wvdz
  • 16,251
  • 4
  • 53
  • 90