ON DUPLICATE KEY UPDATE usage
Hi all,
I'm working on Windows 2003 server with mySQL 4.1.
I'm currently writing a VBScript that pulls down articles written for our company from an XML feed and stores them in a database.
The articles in the feed have an unique id, and sometimes the article is modified once it is published to the feed. The feed is 'queue' based, so articles remain in the feed until it is full, then the oldest article is removed as the new one is added, ad-infinitum.
To deal with the multiple issues of avoiding duplication in the database, and updating existing articles in the database, I made the 'OriginalID' column unique in the schema (this is the id of the articles as provided in the XML feed), as well as my own autoincrement 'ID' column. I then wrote the following SQL Query. However, I am not too confident about my useage of the 'ON DUPLICATE KEY UPDATE' feature. I'd be grateful for any comments.
INSERT INTO articles ( OriginalID , SourceID , Created , Headline , Article , ArticleSummary , PictureURL , PictureURLSmall )
VALUES( ... )
ON DUPLICATE KEY UPDATE Headline=VALUES(Headline), Article=VALUES(Article), ArticleSummary=VALUES(ArticleSummary), PictureURL=VALUES(PictureURL), PictureURLSmall=VALUES(PictureURLSmall);
Thanks in advance for your comments.
- Jamie