在两个条件下插入或更新或更新
solution:的答案在于mysql的插入中...在重复键更新语法上。如果不存在匹配行或更新现有行,则此功能强大的功能可以通过插入新行来进行有效的数据操作。如果违反了唯一的密钥约束。
实现所需的行为,该表必须具有唯一的键定义(在这种情况下为'名称'name'and'dates')。该键用作表中唯一行的标识符。示例方案:Inserting a new row with the following statement will either create a new row or update an existing one, depending on the existence of a row with the same 'name' and 'dates':
insert myThing(name,values1,values2,dates) values (777,1,1,'2015-07-11') on duplicate key update values2=values2 1;
作为示例演示,将...在重复键更新语法上插入...有效地处理基于定义的唯一键的插入和更新操作,从而消除了复杂的存储过程的需求。免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3