关于通过PhpMyAdmin更新表的问题
我是一名数据库初学者,在学习过程中遇到了一个问题。
我现在将通过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使您的更新文件遵循这种格式:
但是,当您有多行具有相同的客户 ID 时,这将更新所有行,这可能不是您想要的。所以你需要另一个 id 字段(如 Ray 所说),它是唯一的,并使用该 id 进行更新
You need to make your update file follow this sort of format:
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
我认为最简单的方法是添加一个额外的标识符字段。
在“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.