create table t(id1 int, id2 int, name varchar(10), constraint pk_t primary key(id1, id2))
insert into t(id1, id2, name)
select 1, 2, '1_2' union all
select 10, 20, '10_20' union all
select 10, 200, '10_200'
go
insert into t(id1, id2, name) values(10, 20, '10_20')
go
select * from t
go
drop table t
go
(3 row(s) affected)
Msg 2627, Level 14, State 1, Line 1
Violation of PRIMARY KEY constraint 'pk_t'. Cannot insert duplicate key in object 'dbo.t'.
The statement has been terminated.
id1 id2 name
----------- ----------- ----------
1 2 1_2
10 20 10_20
10 200 10_200
(3 row(s) affected)