MySQL INSERT statement with steroids
Do you remember when you first learned about basic SQL statements? INSERT, UPDATE, DELETE and SELECT?
While SELECT is a whole different beast, the other three are pretty much the same across different database engines, so you usually learn the basics only.
The thing is, you should REALLY read the documentation for your specific engine, because most of the time, each engine adds cool functionality to the standards (OK, this will break your code when you change from database X to Y, but in the meantime, it makes development so much easier)
How many times, have you written code that looks like this:
1 2 3 4 5 6 7 8 9 | bool exist = CheckIfDuplicate(key); if(!exist) { //insert } else { //update } |
I hope not as many as me... This is the day I learned about:
So if you are not familiar with this syntax and you're a heavy MySQL user, please go read the documentation. Go. Now.