I have a table where I need to insert codes, years, and descriptions. When the table was created, the PKey was Year,Code I'm trying to insert the same code with a different year into the table
So...
Existing values
Year | Code| Description
2016 | A | Code A
2016 | B | Code B
2016 | C | Code C
Attempt to Insert
2017 | A | Code A
2017 | B | Code B
2017 | C | Code C
From what I've read, it sounds like this should be valid. But, for some reason, I keep getting the error that
My SQL is:
select *
into #temp
from code_lkp
insert into code_lkp (year,code,description)
select 2017,code,description
from #temp
drop table #temp
Since the combination of the two columns is unique, shouldn't the table accept the insert?
UPDATE....
I ran
select a.name, b.name, c.name
from sys.sysobjects a
inner join sys.syscolumns b
on a.id = b.id
inner join sys.key_constraints c
on c.parent_object_id = a.id
where a.type = 'U'
and a.name = 'code_lkp'
According to the results:
SysObjects | SysColumns | key_contraints
code_lkp | Year | code_lkp_pk
code_lkp | Code | code_lkp_pk
If I'm not mistaken, this should indicate that both Year and Code are part of the same Primary Key.