how to build self referencing table

前端 未结 1 395
攒了一身酷
攒了一身酷 2021-01-26 22:01

In the source table, there are two columns as following snapshot shows:

\"enter

Th

相关标签:
1条回答
  • 2021-01-26 22:23

    If the column is nullable, then you could load the unique values for location_ID and then have a secondary process come back through and take care of updating existing and possibly adding new.

    Pass 1

    1 NULL A NULL
    2 NULL B NULL 
    3 NULL C NULL
    4 NULL D NULL
    

    I suppose if it's not nullable, then you could precompute those ids in a data flow and assign current row and parent to themselves. As a developer, I might hate you for that though ;)

    Pass 2

    At this point, it becomes a question of whether there should be 8 rows in the table or 4 (whatever your source data indicates). This becomes a question for business users, appropriately "dumbed down". I've seen both answers in my hierarchy questions - "Who does the President report to?" At one place, the President reported to no one which meant expense requests were automatically approved. A different place had the CEO report to themselves which meant their expense reports still had to be approved by themselves. I guess it was to ensure they had executive accountability as nothing was automagic.

    If the answer is 8 rows, then your data flow would look about right. If it's 4, then you'd use the existing data flow but update the rows instead. If it's a small set of rows, hundreds, then you can use the OLEDB Command and write your update statement. Just realize that it will issue an UPDATE statement for every row that hits the component. That can bring your processing to a standstill as it's terribly inefficient.

    The more efficient route for updates is to use the OLE DB destination and the after the Data Flow completed, have an Execute SQL task issue a set-based UPDATE statement. See Andy Leonard's Stairway to Integration Services series for a well written example of how to do this.

    If it's not nullable and nodes referencing themselves is not allowed, then it seems your data model does not accurately describe

    0 讨论(0)
提交回复
热议问题