如何在 MS-Access 中创建相关更新子查询?

发布于 2024-09-10 20:40:55 字数 630 浏览 6 评论 0原文

我正在规范化几个表,并且已向名为 Exams 的表添加了一个代理主键,该表包含考试标题。

以前,子表仅使用考试的完整名称作为 FK 条目。

现在我已经向表中添加了一个自动编号字段,我想更新使用它的条目,例如问题所在的表,因为有超过一千个问题。

每次找到名称后,通过修改后的更新来完成每次考试都需要一段时间,因此我决定在 UPDATE 查询中编写相关子查询。查询如下所示:

UPDATE tblExamQuestion
SET ExamID = (SELECT ExamID FROM tblExam WHERE ExamName = tblExamQuestion.ExamName);

不幸的是,一旦我编写了子查询部分,Access 就拒绝给我运行选项,而只显示设计视图数据表视图< /em> 和该查询的 SQL 视图。但是,它仍然在对象资源管理器中显示“更新查询”图标。

是否有正确的方法来编写此内容,以便 Access 不会感到不安?

使用:Access 2007 和 Access 2003 MDB 数据库。

I'm in the process of normalizing a few tables and I've added a surrogate primary key to a table called Exams which holds exam titles.

Previously, the child tables would just use the entire name of the exam as the FK entry.

Now that I've added a autonumbered field to the table, I want to update the entries that use it such as the table where the questions are from as there are over a thousand of them.

Going through each exam with a modified update once I find the name each time would take a while, so I decided to write a correlated subquery in a UPDATE query. The query looks like this:

UPDATE tblExamQuestion
SET ExamID = (SELECT ExamID FROM tblExam WHERE ExamName = tblExamQuestion.ExamName);

Unfortunately, once I write the subquery portion, Access refuses to give me the Run option and just displays the Design View, Datasheet View and SQL View for that query. However, it still displays the Update Query icon in the object explorer.

Is there a proper way to write this so that Access doesn't get upset?

Using: Access 2007 with a Access 2003 MDB database.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帅哥哥的热头脑 2024-09-17 20:40:55

为什么不:

UPDATE tblExamQuestion
INNER JOIN tblExam 
ON tblExam.ExamName = tblExamQuestion.ExamName
SET tblExamQuestion.ExamID = tblExam.ExamID 

Why not:

UPDATE tblExamQuestion
INNER JOIN tblExam 
ON tblExam.ExamName = tblExamQuestion.ExamName
SET tblExamQuestion.ExamID = tblExam.ExamID 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文