关于通过PhpMyAdmin更新表的问题

发布于 2024-11-17 19:07:04 字数 578 浏览 2 评论 0原文

我是一名数据库初学者,在学习过程中遇到了一个问题。

我现在将通过 phpMyAdmin 导入文本文件来更新数据库的一张表。 除了处理具有相同 customer_ID 的行之外,一切都运行良好。

该行有一个名为“customer_ID”的字段,我无法将其作为主键,因为用于填充数据库的初始文本文件包含单个 customer_ID 的多行,因此数据库必须允许一个用户 ID 包含多行。

我用导入文本文件填充数据库,没有错误。但是,现在我需要使用更新文本文件更新数据库,更新文本文件中的 customer_id 都已存在(填充)在数据库中,因此如果我使用此更新的文本文件更新数据库(通过“导入”) PhpMyAdmin 中的函数),具有相同 customer_ID 的现有行将不会被更新,但将创建具有相同 customer_ID 的另一行,这不完全是我想要的。

我认为这是一个两难的境地,如果我可以将 customer_id 作为主键,则更新过程将完美运行,但由于我需要允许 customer_id 在数据库填充过程中出现在多行中,所以我无法将 customer_id 作为主键钥匙。

请原谅这个小问题。不知道专家可以给我一些建议或一些相关的读物吗?预先感谢您的帮助。

I am a database beginner, I met a problem during my study.

I am now going to update one table of my database by importing a text file through phpMyAdmin.
Everything worked great except for handling with rows that has same customer_ID.

The row has a field called "customer_ID", and I cannot make this a primary key, since the initial text file used to populate the database contains multiple rows for a single customer_ID, so database must allow multiple rows for one user id.

I populated the database with the import text file, no error. However, now I need to update the database with an update text file, the customer_id within the update text file are all already existed(populated) in the database, so if I update the database with this updated text file(through the "import" function in PhpMyAdmin), the existing rows with the same customer_ID will not be updated, but another row with the same customer_ID will be created, which is not exactly what I want.

I think this is a dilemma, if I could make the customer_id a primary key, the update process will work perfectly, but since I need to allow customer_id appearing in multiple rows in the database populating process, so I couldn't make customer_id a primary key.

Please pardon for the trivial question.I wonder if experts could give me some suggestion or some related readings? Thanks in advance for the help.

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

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

发布评论

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

评论(2

隔岸观火 2024-11-24 19:07:04

您需要使您的更新文件遵循这种格式:

UPDATE table SET field1 = value, field2 = value WHERE customer_ID = existing value

但是,当您有多行具有相同的客户 ID 时,这将更新所有行,这可能不是您想要的。所以你需要另一个 id 字段(如 Ray 所说),它是唯一的,并使用该 id 进行更新

...WHERE id = existing value

You need to make your update file follow this sort of format:

UPDATE table SET field1 = value, field2 = value WHERE customer_ID = existing value

However where you have multiple rows with the same customer id that will update all the rows, which is probably not what you want. So you need another id field (as Ray says), which is unique, and update using that id

...WHERE id = existing value
吃素的狼 2024-11-24 19:07:04

我认为最简单的方法是添加一个额外的标识符字段。
在“customer_id”旁边添加一个名为“id”的字段,并将“id”设为主要字段。

I think the easiest way to do this is adding an extra identifier field.
Add a filed called 'id' next to 'customer_id' and make 'id' primary.

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