may be ignored UPDATE statement (update tip) _ Database Other

Source: Internet
Author: User

Oh, the park's brother I have to write a simple article, I hope we do not hesitate to enlighten. This time we're talking about the UPDATE statement in SQL. Here, there will be many brothers are not satisfied, is not the UPDATE statement? Who can't write, update table set column=expression [where search_condition ah.

But does the real UPDATE statement just do that? The essence of it what is the principle of it? We use examples to illustrate:
Suppose there is a score sheet with only two fields, names and grades. How do you query a student's name, score, and rank in a table with an SQL statement?
Oh, this question is the last time I sent the details see http://www.jb51.net/article/53832.htm
The result can go there to see. Now change the question, assuming that the score sheet has three fields, names, grades and rankings, and now only the names and grades have a value, how to update their rankings up?

A friend might come up with a similar solution: first, Query the query, and then update the rankings with the cursor.
Is there a better solution? Of course there is, the answer is to use the UPDATE statement.

Update score Table Set rank = (SELECT count (*) +1 from the score table where a. Achievements < accomplishments)
From Performance form a

As you can see, it's implemented with just one statement. At the same time, we can find that it is different from the UPDATE statement we usually write. in fact, the principle of the UPDATE statement is similar to the SELECT statement, and the complete UPDATE statement should be the Update table set column=expression from table [where search_condition], A section of the following is a complete query statement . When the table of the update and the table of the query (that is, the table from behind) are exactly the same, they can be omitted and written in our most common Update table set column=expression [where Search_ Condition].

The above is just an example to illustrate the use of update, real development, flexible and appropriate use of update can achieve a multiplier effect oh.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.