
Violation of PRIMARY KEY problem
Hi all.
SQL 2k Dev ed
Win 2k Pro
I have a "Link table" to store link IDs between two other tables
LinkTable
ID1 INT
ID2 INT
Primary Key = ID1, ID2
I call a stored Proc (from ASP)
MyProc (title, description, links)
it adds a new row with the title & description and gets the new ID
back for row.
then I add links into the link table, the links are passed into the
stored proc as a string with numbers seperated by commas
eg links = "1,2,3,4,5,3,6,7'
the function dbo.fn_intlist_to_table() returns the links list as a
table with 8 rows 1 column.
What I want to add into the Link table is the following values.
NewID, 1
NewID, 2
NewID, 3
NewID, 4
NewID, 5
NewID, 3 <<<< Except for this one!!!
NewID, 6
NewID, 7
but as you can see the number "3" is in the links list TWICE... which
means when it adds it to the LinkTable it fails with the following
error:
Violation of PRIMARY KEY constraint 'PK_LinkTable '. Cannot
insert duplicate key in object 'LinkTable'.
This is the Code I'm using to put the values into the LinkTable
INSERT INTO LinkTable (ID1, ID2)
How can I do the same thing but if the row already exists in the
LinkTable just ignore the current link and move onto the next one.
Thanks for any help on this.
Alan