Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql SQL:Insert或Update命令_Mysql_Sql - Fatal编程技术网

Mysql SQL:Insert或Update命令

Mysql SQL:Insert或Update命令,mysql,sql,Mysql,Sql,我正在使用“Voila Norbert”API,我想将结果存储在一个DB表中,如下所示: email_Norbert ( id Integer(11) NOT NULL AUTO_INCREMENT, idUser Integer(11) NOT NULL, email VarChar(50) CHARACTER SET latin1 COLLATE latin1_swedish_ci, score Integer(2), existence TinyInt(1),

我正在使用“Voila Norbert”API,我想将结果存储在一个DB表中,如下所示:

email_Norbert (
id    Integer(11) NOT NULL AUTO_INCREMENT,
idUser    Integer(11) NOT NULL,
email     VarChar(50) CHARACTER SET latin1 COLLATE latin1_swedish_ci,
score     Integer(2),
existence TinyInt(1),
PRIMARY KEY (
        id
)
实际上,我使用这个查询(例如,我设置了值,但每次都会为每个idUser更改):

插入运行良好,但当记录已经存在时,我确实添加了另一条记录


我该怎么办?

如果希望同一用户的后续插入失败,而不是更新,请在iduser列上添加唯一索引

create unique index email_Norbert_u1 on email_Norbert(iduser)

我不知道我出名了…哈哈:D.有什么想法吗?我不确定我是否理解,但如果你期望插入失败,那么你应该将主键设置为包含idUser alsodo。你需要重复键语法。您唯一的密钥是insert语句中没有的增量列,因此我怀疑它是否会触发!或者,如果您希望插入失败,请在iduser fieldWorking上放置唯一索引!非常感谢:DI只晚了3秒,我也得到了解决方案:P,但为了进一步澄清,我想说,对于更新操作,至少有一列必须是唯一的。
create unique index email_Norbert_u1 on email_Norbert(iduser)