When I opened my blog, I found that it has been nearly a month since the last article was published. The concept of time has become so terrible at this moment... Find a reason for yourself. It's because it hasn't been updated for so long... Well, I really don't want to look for reasons like busy work, bad mood, and nothing to write. I made a decisive review-I am lazy.
I suddenly realized that many blog communities, including cnblog, are very interesting. I remember that I was very dissatisfied when I started to write a BLOG. I also wanted to talk about it in BOLG, there are a lot of "awesome" experiences, "exclusive" technical points plus a bit of "humorous" strokes, why are they so indifferent? The feeling of smiling I want to express is often referred to as "casual ". Google now-the so-called "Essay" is just a transcript, with a short length, including lyrical, narrative, or comment. I want to put it in today's BOLG. The "casual" mood may be more casual, big or small, rough or refined, but it can be set to be written on a daily basis, you can feel it as you like. The word "casual writing" describes the essence of a BLOG. SO, I will write my own BLOG more casually, reminding myself not to write anything for a month. Although it won't force your own frequency, it doesn't mean your life has failed if you haven't felt it for a month -_-!..
End your statement. Today, I will summarize my recent experiences in designing databases for game servers. I once again feel that database design is really a science. What technologies are getting deeper and deeper.
Replace into Statement of MySQL:
When designing the character card data table logic, we encountered a common headache:
1. First, determine whether the card data exists. 2. If the card data of this role does not exist, insert the data. 3. If the data exists, update the data.
Of course
If not exists (select id from t where id = 1) // determine whether this ID data exists insert into t (id, data) values (1, data) // if it does not exist, insert into a specified data else update t set data = data where id = 1 // if it exists, update the ID data
This logic is not complicated, but after all, this operation requires two database statements to be executed, and I am very lazy, so MySQL's replace into Debut:
replace into t(id, data) values(1,data)
The logic here is:ReplaceThe statement first tries to insert data into the table. If the table already contains this row of data (), it first deletes this row of data and then inserts new data. Otherwise, it inserts new data directly.
One sentence! The role of replace into is equivalent to implementing the logic of the above problem. The above situation is its typical application. Note that replaceThe statement must be supported by a primary key or a unique key. Otherwise, it is only equivalent to an insert into statement!