Jump to content
  • Advertisement
Sign in to follow this  
39ster

SQL Update OR Insert

This topic is 3612 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm using sqlite in a game that i'm developing. I was just wondering if there is any SQL syntax to automatically insert a row into a table if the primary key doesn't exist, and if the primary key does already exist, then update? At the moment i'm always doing "SELECT" to check if the row item already exists in the database, and if it doesn't exist then write a separate SQL for INSERT and if it does exist then write a separate SQL for UPDATE and it's annoying.

Share this post


Link to post
Share on other sites
Advertisement
Check out the SQLite documentation: http://sqlite.org/lang_insert.html

The magic words are "INSERT OR REPLACE".

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!