Paste this into a new question or an answer at dba.stackexchange.com:
<!-- --> > create table t ( a int, b int, c int, d int) ; > > <pre> > ✓ > </pre> <!-- --> > alter table t add unique(b, c); > > <pre> > ✓ > </pre> <!-- --> > insert into t (a, b, c, d) values (1, 1, 1, 1), (2, 2, null, 2), (3, 2, null, null); > > <pre> > Msg 2627 Level 14 State 1 Line 1 Violation of UNIQUE KEY constraint 'UQ__t__A86D1816EDACB3D3'. Cannot insert duplicate key in object 'dbo.t'. The duplicate key value is (2, &lt;NULL&gt;). Msg 3621 Level 0 State 0 Line 1 The statement has been terminated. > </pre> <!-- --> > select * from t; > > <pre> > a | b | c | d > -: | -: | -: | -: > </pre> *db<>fiddle [here](https://dbfiddle.uk/?rdbms=sqlserver_2019l&fiddle=34cab8ba7d74b488d215a96f7e83c096)*
back to fiddle