tags:

views:

145

answers:

3

Is there mysql's INSERT IGNORE equivalent in MS SQL Server 2005 or something similar?

+1  A: 

you can implement something like this with an INSTEAD OF trigger, intercepting the default insert action to perform updates where existing rows are detected. Not quite as out-of-the-box as the MySql variation, but more flexible.

davek
A: 

I don't know what your application is - maybe the REPLACE could help?!

Philipp Andre
No such functionality in MS SQL Server apart from text replace. There is a MERGE but SQL2008 only.
Martin Smith
+1  A: 

I'm not familiar with the mysql INSERT IGNORE feature, but the documentation I am reading makes it sound like all it does is ignore(silently fail) attempts to insert a record with a primary key that already exists in the table.

If that is what you are looking for, SQL Server has a similar functionality, but you have to apply it to the primary key or unique constraint when you create it.

Read about the IGNORE_DUP_KEY option of a unique index.

Chris Shaffer
IGNORE_DUP_KEY is what I was looking for, thanks.
JohnM2
Unfortunately it doesn't work as I thought it will. It doesn't issue an error but it gives a warning which is also not a solution form me.
JohnM2