Mysql 使用单个查询更新数据库中的一组数据(删除一些条目并添加一些条目)
假设我有一个可以与Mysql 使用单个查询更新数据库中的一组数据(删除一些条目并添加一些条目),mysql,sql,database,Mysql,Sql,Database,假设我有一个可以与k类别关联的产品。简化的数据库结构: // Table for products product - pid - name // Table for categories category - cid - name // table associating a product with categories product_category - pcid - pid - cid 假设当前系统状态已将产品与一组类别关联。前 Product: Dell XPS Laptop
k
类别关联的产品。简化的数据库结构:
// Table for products
product
- pid
- name
// Table for categories
category
- cid
- name
// table associating a product with categories
product_category
- pcid
- pid
- cid
假设当前系统状态已将产品与一组类别关联。前
Product: Dell XPS Laptop
Categories: Laptop, Electronics, Dell
稍后,管理员提交一组更新的类别,从产品中删除Dell
,并添加计算机
。管理员还可以随时删除多个类别并添加多个类别
我可以通过以下几种方法中的一种,使用两个步骤完成此操作: