简体   繁体   English

将MYSQL查询更新更改为REPLACE INTO

[英]Change MYSQL Query UPDATE to REPLACE INTO

The query seems to be easy enough to convert as I have very specific requirement, if it exists just update else insert. 该查询似乎很容易转换,因为我有非常具体的要求,如果存在,则只需更新其他插入即可。 But I am having really hard time converting it..probably because of multiple joins it is using. 但是我很难转换它..可能是因为它正在使用多个联接。 There is a catch to it though, there is no primary key.I would really appreciate it if someone take a crack at it and make my life easier ... :-) 但是有一个陷阱,没有主键,如果有人破解它并让我的生活更轻松,我将非常感激... :-)

There are only three columns for the table 该表只有三列

ASSET_ASSOCIATION
-----------------

ASSET_ID | ASSET_FIELD_ID | ASSET_ASSOCIATED_ID

10        46               15
12        46               37
10        21               8

Query I am using is 我正在使用的查询是

..... .....

Is there any hope for me ?? 我有什么希望吗? Would really appreciate any help ..... 非常感谢任何帮助.....

http://dev.mysql.com/doc/refman/5.6/en/replace.html http://dev.mysql.com/doc/refman/5.6/en/replace.html

REPLACE works exactly like INSERT , except that if an old row in the table has the same value as a new row for a PRIMARY KEY or a UNIQUE index , the old row is deleted before the new row is inserted. REPLACE工作原理与INSERT完全相同,不同之处在于,如果表中的旧行与PRIMARY KEY或UNIQUE索引的新行具有相同的值,则在插入新行之前会删除旧行。

No primary key or unique index, no REPLACE , full stop. 没有主键或唯一索引,没有REPLACE ,句号。

A table without a primary key is (almost always) a huge mistake. 没有主键的表(几乎总是)是一个巨大的错误。 Get in touch with the DBA (or someone with sufficient privilege) and let him/her know there is no primary key on the table. 与DBA(或具有足够特权的人)联系,并让他/她知道表上没有主键。 S/he will add the primary key without you asking for it. 他/他将添加主键,而无需您提出要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM