如何消除 MS Access 2003 中具有唯一 ID 的重复条目?
我正在开发一个包含大量重复条目的 MS Access 数据库。问题是有一个学生表,有时有人会用不同的 ID 再次添加该学生,而不是仅仅更新某个学生的信息。我想删除所有重复项(这很痛苦,因为几乎没有任何方法可以区分它们),只需删除重复项就可以了,但其他表可能依赖于重复项。如何将依赖某个 ID 的所有表更改为依赖我选择保留的 ID?
它看起来是这样的:
Student ID | L. Name |F. Name ANDY-01 | Andy | Andy ANDY-02 | Andy | Andy
然后在课程表中,我有 ANDY-01 会修读的课程,以及 ANDY-02 会修读的课程。我想将所有表中包含 ANDY-01 和 ANDY-02 的所有条目合并为 ANDY-01。我该怎么办呢?
(不用担心我如何区分 ANDY-01 和 ANDY-02)
I'm working on an MS Access Database with tons of duplicate entries. The problem is that there is a table of students, and sometimes instead of just updating a certain student's information, someone would just add the student in again with a different ID. I want to get rid of all the duplicates (which is a pain since there's barely any way to differentiate them), which would be fine by just deleting the duplicates, except that other tables may rely on the duplicate. How can I change all the tables that rely on a certain ID to rely on the ID that I choose to keep?
Here's what it looks like:
Student ID | L. Name |F. Name ANDY-01 | Andy | Andy ANDY-02 | Andy | Andy
Then in the courses table I'd have courses that ANDY-01 would have taken, and courses ANDY-02 would have taken. I want to merge all entries in all the tables that would have ANDY-01 and ANDY-02 as ANDY-01. How would I go about this?
(Don't worry about how I'm differentiating between ANDY-01 and ANDY-02)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Riho的回答+1。要更新多个表,您可以创建如下所示的过程,然后手动更新 ID 值并为每个学生执行该过程。
如果您有一个映射新旧 ID 的表或查询,您可以编写另一个过程来读取该表并为每个学生调用此过程。
+1 for Riho's answer. To update multiple tables you could create a procedure like the one below, and manually update the ID values and execute the procedure for each student.
If you have a table or query that maps the old and new IDs you could write another procedure to read the table and call this procedure for each student.
您只需执行一些更新 SQL:
update another_table set Student_id=:ID2 where Student_id=:ID1
You just have to make some update SQL:
update another_table set student_id=:ID2 where student_id=:ID1