How do I split flat file data and load into parent-child tables in database?

前端 未结 2 816
一个人的身影
一个人的身影 2020-12-06 06:54

I have denormalized data (coming from a file) that needs to be imported into parent-child tables. The source data is something like this:

Account#    Name           


        
2条回答
  •  离开以前
    2020-12-06 07:28

    If the data is sorted and Account# is an integer I would:

    Insert the emails into a table (add an auto increment column, it's a best practise).

    1  101    alpha@foo.com
    2  101    bravo@foo.com
    3  101    charlie@yay.com
    etc.
    

    Then I would insert the other records to a parent table.

    • using Account# as the primary key
    • omitting the email addresses
    • skipping duplicates (easy if the data is sorted).

    If you have a foreign key relationship setup, you will need to do the second step first (to avoid having any orphan records).

    My two cents: I don't know what your requirements are but it seems a bit over-normalized. If there is a small limit on the number of email addresses, I would consider adding several email columns to the main table...for speed and simplicity.

提交回复
热议问题