David said:
So in problem set seven, we give you this one line of code, which long story short, solves this problem in MySQL. This very long instruction that doesn't even fit onto one line on the screen here ensures that your operation is what's called atomic. It all happens at once, or it doesn't happen at all. This very long phrase cannot get interrupted partially. And what it does is literally what it says. Insert into some table the following three fields those specific values, but on duplicate key, don't do an insert. Do an update. So this is like doing a SELECT and an INSERT so to speak at the same time. And what is the key that's probably being referred to here? It turns out, and you'll see this in problem set seven's spec, because we've declared there to be a unique key on this particular table such that you can't have multiple rows for the same user with the same penny stock symbol-- in this example here, DVN.V is a silly penny stock that we refer to in the spec. Because we've declared it to be unique, what this means is that if you try to insert a duplicate row, you're instead going to update it without anyone else having a chance to change the state of the world either. So in short, this ensures things are atomic.
But what exactly does this mean? How do a SELECT and INSERT and the same time help solve the problem? And what's with all the 'key' thing?
Also, he then said that the Start Transaction will fix the problem, making the transaction happen at the same time. WHY?