Oracle:迁移期间规范化数据
我有一个包含大量重复数据的表,我想将其重构为 3 个表。
当前结构如下所示:
meeting_desc
meeting_date
topic_desc
...
current_table 中的数据如下所示:
meeting1,2/3/2009,abc
meeting1,2/3/2009,efg
meeting1,2/3/2009,xyz
meeting2,4/5/2009,aaa
meeting2,4/5/2009,bbb
我想创建一个会议表和一个主题表,其中 PK 来自序列:
MEETING:
id
meeting_desc
meeting_date
TOPIC:
id
meeting_id
topic_desc
我不知道如何将数据插入到新表中。我已经尝试过了:
insert into MEETING select distinct
seq.nextval, meeting_desc, meeting_date from current_table
但这当然行不通。有没有一种简单的方法来标准化数据?
I have a table with a lot of repeated data that I'd like to refactor as 3 tables.
Current structure looks like:
meeting_desc
meeting_date
topic_desc
...
And the data in the current_table looks like:
meeting1,2/3/2009,abc
meeting1,2/3/2009,efg
meeting1,2/3/2009,xyz
meeting2,4/5/2009,aaa
meeting2,4/5/2009,bbb
I would like to create a meeting table and a topic table, with PKs coming from a sequence:
MEETING:
id
meeting_desc
meeting_date
TOPIC:
id
meeting_id
topic_desc
What I can't figure out is how to insert data into the new tables. I've tried:
insert into MEETING select distinct
seq.nextval, meeting_desc, meeting_date from current_table
but of course that doesn't work. Is there an easy way to normalize the data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
放置在子查询中的
DISTINCT
应该可以工作:完成此操作后,您可以将这个新创建的表与旧表连接起来,以将生成的 id 与子表相关联:
The
DISTINCT
placed in a subquery should work:Once this is done, you would join this newly created table with the old table to associate the generated ids to the children tables: