简体   繁体   English

SQL仅替换为一行的前两列

[英]SQL replace into only the first two columns in a row

What I currently have is this: 我目前所拥有的是:

PreparedStatement ps = getSQLConnection().prepareStatement(
    "REPLACE INTO " + table + " (uuid,name) VALUES(?,?)"
    );

ps.setString(1, uuid.toString());
ps.setString(2, name.toLowerCase());
ps.executeUpdate();

However it is not setting only index 1 and 2, but instead clears the other column values. 但是,它不仅设置索引1和2,而且清除其他列值。 How can I insert into a row with only the first 2 indexes, and leave the other values untouched? 如何仅插入前两个索引的行,而保持其他值不变?

The table is created with this statement: 该表使用以下语句创建:

"CREATE TABLE IF NOT EXISTS data (" +
"`uuid` varchar(36) NOT NULL," +
"`name` varchar," + 
"`owner` varchar," + 
"`tags` varchar," + 
"PRIMARY KEY (`uuid`));"

From the documentation : 文档中

REPLACE is a MySQL extension to the SQL standard. REPLACE是MySQL对SQL标准的扩展。 It either inserts, or deletes and inserts. 它要么插入,要么删除并插入。 For another MySQL extension to standard SQL—that either inserts or updates—see Section 13.2.5.3, “INSERT ... ON DUPLICATE KEY UPDATE Syntax”. 有关插入或更新的标准SQL的另一个MySQL扩展,请参见第13.2.5.3节“在双重键更新语法上插入...”。

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

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