词条 | Merge (SQL) |
释义 |
A relational database management system uses SQL UsageA right join is employed over the Target (the INTO table) and the Source (the USING table / view / sub-query)--where Target is the left table and Source is the right one. The four possible combinations yield these rules:
If multiple Source rows match a given Target row, an error is mandated by SQL:2003 standards. You cannot update a Target row multiple times with a MERGE statement ImplementationsDatabase management systems Oracle Database, DB2, Teradata, EXASOL, Firebird, CUBRID, HSQLDB, MS SQL, Vectorwise and Apache Derby support the standard syntax. Some also add non-standard SQL extensions. {{anchor|upsert}} SynonymousSome database implementations adopted the term "Upsert" (a portmanteau of update and insert) to a database statement, or combination of statements, that inserts a record to a table in a database if the record does not exist or, if the record already exists, updates the existing record. This synonym is used in PostgreSQL (v9.5+)[1] and SQLite (v3.24+).[2] It is also used to abbreviate the "MERGE" equivalent pseudo-code. It is used in Microsoft SQL Azure.[3] Other non-standard implementationsSome other database management systems support this, or very similar behavior, through their own, non-standard SQL extensions. MySQL, for example, supports the use of {{code|lang=mysql|INSERT ... ON DUPLICATE KEY UPDATE}} syntax[4] which can be used to achieve a similar effect with the limitation that the join between target and source has to be made only on PRIMARY KEY or UNIQUE constraints, which is not required in the ANSI/ISO standard. It also supports REPLACE INTO as an alias for compatibility with MySQL.[7]Firebird supports IBM DB2 extends the syntax with multiple Microsoft SQL Server extends with supporting guards and also with supporting Left Join via {{code|lang=tsql|WHEN NOT MATCHED BY SOURCE}} clauses. PostgreSQL supports merging via {{code|2=sql|INSERT INTO ... ON CONFLICT [ conflict_target ] conflict_action}}.[8]CUBRID supportsMERGE INTO [9] statement. And supports the use of {{code|lang=mysql|INSERT ... ON DUPLICATE KEY UPDATE}} syntax.[10] It also supports REPLACE INTO for compatibility with MySQL.[11]Apache Phoenix supports See also
References1. ^PostgreSQL-tutorial 2. ^upsert sqlite.org visited 6-6-2018 3. ^[https://msdn.microsoft.com/en-us/library/bb510625.aspx Transact-SQL Reference (Database Engine): MERGE (Transact-SQL)] 4. ^MySQL :: MySQL 5.1 Reference Manual :: 12.2.4.3 INSERT ... ON DUPLICATE KEY UPDATE Syntax 5. ^MySQL 5.1 Reference Manual: 11.2.6 REPLACE Syntax 6. ^{{cite web|title=MySQL 5.5 Reference Manual :: 13.2.5 INSERT Syntax|url=http://dev.mysql.com/doc/refman/5.5/en/insert.html|accessdate=29 October 2013}} 7. ^{{cite web|url=http://www.sqlite.org/lang_insert.html|title=SQL As Understood By SQLite: INSERT|accessdate=2012-09-27}} 8. ^PostgreSQL INSERT page 9. ^{{cite web|url=http://www.cubrid.org/blog/news/announcing-cubrid-9-0-with-3x-performance-increase-and-sharding-support|title=New CUBRID 9.0.0|publisher=CUBRID Official Blog|date=2012-10-30|accessdate=2012-11-08}} 10. ^CUBRID :: Data Manipulation Statements :: Insert :: ON DUPLICATE KEY UPDATE Clause 11. ^CUBRID :: Data Manipulation Statements :: Replace 12. ^{{cite web|url=https://phoenix.apache.org/language/#upsert_values|title=UPSERT VALUES}} 13. ^{{cite web|url=https://phoenix.apache.org/language/#upsert_select|title=UPSERT SELECT}}
External links
2 : SQL keywords|Articles with example SQL code |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。