mySQL 导入/重复键
我正在编写一个数据库,需要能够从另一个数据库导入信息。我的数据库有一个成员表和另一个用于成员可能被授予的权限的表(一个成员可能被授予多种类型的权限)。成员表包含一列来存储来自其他数据库的成员的主键,以便顺利导入。
我的问题是,当我从另一个数据库导入另一个数据库密钥和权限,然后将“其他密钥”转换为我的密钥时,我可能会复制权限表中的条目,而 mySQL 正确地不允许这样做。我希望它能够继续更改它可以更改的内容,并且我知道可以删除那些未更改的内容。
有人可以帮助我,或者有完全不同的解决方案吗?
I am writing a database that needs to be able to import information from another database. My database has a table for members and another table for permissions that members may be granted (a member may be granted more than one type of permission). The members table contains a column to store the primary key for members from the other DB for the purpose of smooth imports.
My problem is that when I import the other DB key and permission from the other database then turn the "other keys" into my keys, I am likely duplicating entries in the permissions table, which mySQL correctly will not allow. I would like it to go ahead and change the ones it can and I know the ones that are not changed I can delete.
Can someone help me, or have an altogether different solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需在查询中添加
IGNORE
并删除not in
即可。然后,重复错误将被视为警告,并且您将仅使用唯一数据继续导入。您无需返回并手动删除重复项。Just add a
IGNORE
to your query and lose thenot in
. Duplicate errors are then regarded as warnings and your import will continue with just the unique data. You don't need to comeback and delete the duplicates by hand.