无法从指定的表中删除

时间:2015-10-30 19:47:50

标签: ms-access

我需要删除Table1中具有Table2中相应ID的所有数据。我用过:

DELETE Table1.*
FROM Table1 INNER JOIN Table2 ON Table1.ID=Table2.ID

我运行它并收到错误消息“无法从指定的表中删除”

我也尝试了一些我在这里找到的建议并将查询更改为

DELETE Table1.*
FROM Table1 INNER JOIN Table2 ON Table2.ID=Table1.ID

但得到同样的错误

1 个答案:

答案 0 :(得分:4)

Apparently your JOIN has created a query that is not updateable. This is usually because one or both IDs are not primary keys or have no unique index. More reasons can be found here or here. If this cannot be corrected, use an IN clause instead: DELETE Table1.* FROM Table1 WHERE Table1.ID IN (SELECT Table2.ID FROM Table2) It will be slower than a INNER JOIN, but should work.