如何在 MySQL 中删除多行 2 列作为复合主键? [英] How to delete multiple rows with 2 columns as composite primary key in MySQL?

查看:60
本文介绍了如何在 MySQL 中删除多行 2 列作为复合主键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的innodb表结构如下:4列(CountryID, Year, %Change, Source),其中2列(CountryID, Year)为主钥匙.除了使用 for 循环删除每一行之外,如何删除多行?

My innodb table has the following structure: 4 columns (CountryID, Year, %Change, Source), with the 2 columns (CountryID, Year) as the primary key. How do I delete multiple rows other than using a for-loop to delete each row?

我正在寻找类似的东西

DELETE FROM CPI 
 WHERE CountryID AND Year IN (('AD', 2010), ('AF', 2009), ('AG', 1992))

推荐答案

Oracle 中的答案是:

The answer in Oracle is:

delete from cpi
 where (countryid, year) in (('AD', 2010), ('AF', 2009), ('AG', 1992))

这是相当标准的 SQL 语法,我认为 MySQL 是一样的.

It's fairly standard SQL syntax and I think MySQL is the same.

这篇关于如何在 MySQL 中删除多行 2 列作为复合主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆