Sql Server XML-type column duplicate entry detection

Posted by aaaa bbbb on Stack Overflow See other posts from Stack Overflow or by aaaa bbbb
Published on 2010-03-09T18:12:20Z Indexed on 2010/05/02 1:17 UTC
Read the original article Hit count: 223

Filed under:
|

In Sql Server I am using an XML type column to store a message. I do not want to store duplicate messages.

I only will have a few messages per user. I am currently querying the table for these messages, converting the XML to string in my C# code. I then compare the strings with what I am about to insert.

Unfortunately, Sql Server pretty-prints the data in the XML typed fields. What you store into the database is not necessarily exactly the same string as what you get back out later. It is functionally equivalent, but may have white space removed, etc.

Is there an efficient way to compare an XML string that I am considering inserting with those that are already in the database? As an aside, if I detect a duplicate I need to delete the older message then insert the replacement.

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about Xml