In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use update set from in the sql update sentence, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Execute the general sql update statement as update table_name set column_name=value where column_name1=value1 However, we sometimes need to update the fields used in one table into the data of a field in another table according to the relevant fields in two tables, that is, the primary key aid in table a has a foreign key bid related in table b, and the field in table b needs to be updated to the data of field c in table an according to the corresponding id in tables an and b. If updating one by one according to the above sql will be very time-consuming, so we need to use the statement usage of update set from.
There is a table in the database called student, as follows:
If from the real point of view, in a student table, then some people's age is entered incorrectly, then we need to correct these errors, in the case of a very large amount of data, the data is very time-consuming to modify, so we can use an excel table to core all the student information, and then import it into the database to become a temporary table.
The following is the temporary table we imported:
Where student_id is the generated guid, so we now need to update their age based on the name and execute the following sql statement:
Update student set age=tm.age from temporary tm where student.name=tm.name
After successful execution, you can see that our student table has been updated successfully:
Note: update, delete and other statements can not be undone after execution, return. Therefore, you have to be careful when operating. If you are worried about operational errors, you can first back up the database, or create two identical tables, execute them once, and then execute them in the formal table after success.
Thank you for reading this article carefully. I hope the article "how to use update set from in sql update sentence" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
This article focuses on "how to use conditional comments to judge browsers". Interested friends may wish to take a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use conditional comments to judge browsers!
Wechat
About us
Contact us
Product review
car news
thenatureplanet
More Form oMedia:
AutoTimes.
Bestcoffee.
SL News.
Jarebook.
Coffee Hunters.
Sundaily.
Modezone.
NNB.
Coffee.
Game News.
FrontStreet.
GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.