Usage of merge-using in SQL Server

Source: Internet
Author: User

Prior to execution:

Merge into UserInfo u using chartinfo C on U.userid=c.userid if matched and u.username=c.username then update set U.lastupdate=c.lastupdate when is not matched--cannot be update for not matched (no match succeeded of course cannot update) then Insert (Username,sex) VALUES (' Zhangzhao ', ' B ');

After execution


The merge and using collocation is used for data statistics and analysis in particular on BI, such as requiring data that is not in the child table, then the parent table will delete the corresponding data to ensure that the data corresponding to the child table and the parent table is followed by the usual practice of running a job and then passing the cursor/table-valued Function/ Temporary tables and so on loop fetch data and then update the parent table It's a waste of efficiency. Then the merge comes in handy.

Usage of merge-using in SQL Server

Related Article

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.