MyBatis Magic Hall: Batch update operations for each database

Source: Internet
Author: User
Tags mssql

First, preface

The MyBatis update element is used in the same way as the insert element, so this article is not intended to be repeated. This article only records the SQL statement of the bulk update operation, and understands the SQL statements, then the operation of the MyBatis section is simple.

Note: The following bulk update statements are performed as a whole, either all successful or all rolled back.

Ii. SQL statements for MSSQL

With R as (SELECT'John'  asName -  asAge the  asID UNION all SELECT'Mary'  asName -  asAge +  asID UNION all SELECT'Kite'  asName +  asAge -  asID) UPDATE tstudent SET name= R.name, age =r.agefrom R WHERE r.id= Tstudent.id

Iii. SQL statements for MSSQL, Oracle, and MySQL

UPDATE tstudent SET Name = r.name, age =R.age from(SELECT'Mary'  asName A  asAge the  asidunion AllSelect 'John'  asName, -  asAge +  asID) asRwhereID = R.id

Iv. SQL statements for SQLite

When the article is updated:

REPLACE into Tstudent (Name, age, ID) VALUES ('Mary'42 )

Batch update:

 replace into Tstudent (Name, age, ID) SELECT  *  from ( select    mary    as  A,  B, 42  as   C UNION ALL  select   " john   " as  A, 14  as  B, 43  as   b) as R  

Description: REPLACE into determines whether an insert operation or an update operation is performed based on the primary key value.

V. Summary

This article highlights the benefits of MyBatis as a semi-automatic ORM framework, full manual manipulation of SQL statements how a cool word. However, the code farmers of the SQL knowledge requirements have also increased a lot, if the project requirements for these two times the package that will be less easily.

Respect the original, reprint please indicate from: http://www.cnblogs.com/fsjohnhuang/p/4078999.html ^_^ Fat Boy John

Vi. references

http://feng10251225.blog.163.com/blog/static/6312279820114302391320/

Http://www.cnblogs.com/liping13599168/archive/2011/05/24/2054908.html

MyBatis Magic Hall: Batch update operations for each database

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.