douyong2531 2015-02-06 18:28
浏览 244
已采纳

Sql使用重复键插入

Ok so, im still a beginner in databases. i have this code

$sql="INSERT INTO complaints_members(password, complaint) VALUES ('$mypassword','$submit') ON DUPLICATE KEY UPDATE complaint='$submit' ; ";

This simply updates my complaint in the existing entry. How can i insert a new entry with the same key, instead of updating the old one?

Im thinking of it like this.

1st entry is like

Password : 123

Complaint : abc

2nd would be like

Password : 123

Complaint : def

Im not very familiar with the terms of SQL, so i'm sorry in advance, and thanks for your time.

EDIT: This is how the tables are

enter image description here

  • 写回答

3条回答 默认 最新

  • duanqi6274 2015-02-06 18:34
    关注

    You can't have duplicate primary keys in a database. This is intentional.

    Instead, consider re-designing your database so that each complaint has a unique ID (AKA a Primary Key). You should set it as something like complaint_id or simply id, and make it a PK (Primary Key) and AI (Auto-Increment). That way, when you do inserts you won't have to worry about updating the same row.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏