SQL 删除查询错误消息:“指定包含您要删除的记录的表”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6710011/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Delete query error message:"specify the table containing records u want to delete"
提问by Nathaniel_613
I want to delete all records from table "T" if the records are also in table D, but I am getting the error message "SPECIFY THE TABLE CONTAINING THE RECORDS YOU WANT TO DELETE".
如果记录也在表 D 中,我想从表“T”中删除所有记录,但我收到错误消息“指定包含您想要删除的记录的表”。
DELETE T.DISCOUNT_CODE, T.PART_ID, T.SELLING_UM, T.QTY_BREAK_1, T.QTY_BREAK_2, T.QTY_BREAK_3, T.QTY_BREAK_4, T.QTY_BREAK_5, T.QTY_BREAK_6, T.QTY_BREAK_7, T.QTY_BREAK_8, T.QTY_BREAK_9, T.QTY_BREAK_10, T.UNIT_PRICE_10, T.UNIT_PRICE_3, T.UNIT_PRICE_4, T.UNIT_PRICE_5, T.UNIT_PRICE_6, T.UNIT_PRICE_7, T.UNIT_PRICE_8, T.UNIT_PRICE_9, T.UNIT_PRICE_2, T.UNIT_PRICE_1, T.DEFAULT_UNIT_PRICE
FROM SYSADM_DISCOUNT_PRICE AS T
INNER JOIN D ON T.PART_ID = D.PART_ID;
回答by BAKeele
You don't specify columns in a delete statement. You also can't join on delete statements.
您不在删除语句中指定列。您也不能加入删除语句。
Basically, you delete from table . So, put all your conditional logic in a where clause.
基本上,您从 table 中删除。因此,将所有条件逻辑放在 where 子句中。
Where recordid in (select .........)
其中记录ID(选择......)
回答by HansUp
Create a new query in Access, switch to SQL View and paste this in:
在 Access 中创建一个新查询,切换到 SQL 视图并将其粘贴到:
DELETE
FROM SYSADM_DISCOUNT_PRICE AS T
WHERE Exists (SELECT * FROM D WHERE D.PART_ID = T.PART_ID);
That should work if you "run" (execute) the query. If you want to View the affected rows without actually doing the DELETE, you can switch the query designer view to Datasheet View. That will show you which rows will be subject to deletion, but Datasheet View only displays them ... doesn't delete them. However, in order to switch to datasheet view, you will have to tell the query designer which fields to display. You can do that by changing the first line to DELETE *
.
如果您“运行”(执行)查询,那应该可以工作。如果您想查看受影响的行而不实际执行 DELETE,您可以将查询设计器视图切换到数据表视图。这将显示哪些行将被删除,但数据表视图只显示它们......不会删除它们。但是,为了切换到数据表视图,您必须告诉查询设计器要显示哪些字段。您可以通过将第一行更改为DELETE *
.
Another approach would be to change the first line to SELECT *
in order to view the affected records, then change back to DELETE when you're ready to delete them.
另一种方法是将第一行更改SELECT *
为 以查看受影响的记录,然后在您准备删除它们时更改回 DELETE。
回答by Taryn
MS Access does let you join on a delete. So you can write you DELETE statement like this without naming the columns.
MS Access 确实允许您加入删除操作。因此,您可以像这样编写 DELETE 语句而无需命名列。
DELETE T.*
FROM SYSADM_DISCOUNT_PRICE AS T
INNER JOIN D ON T.PART_ID = D.PART_ID;