Truncate All Tables Part 2

  • Comments posted to this topic are about the item Truncate All Tables Part 2

  • Hello there,

    when i execute part1 and part2 together the whole query is executing properly, but it is not restoring the FK constraints properly.

    can anybody help me on this regard?.....



    No Dream Is Too Big....!

  • What's seems to be the problem

  • I've a database which has, two dimension and one fact table.

    when i run the script, it is restoring primary keys successfully, but not FK relations in the fact table.

    I mean my fact table doesn't hold any relation with the dimension tables after running the script.

    Please tell me what might be the problem?.. is it with my database or script?



    No Dream Is Too Big....!

  • One of the problems that I see a lot is that when trying to restore the relationship there are orphans on the tables. Ensure that all the foreign keys from the parent are present on the tables. For example. If table A has ID ( 1,2,3,4,5,6) and a child table B has the FK's (1,4,5,6) After dropping all the constraints we delete the records (5,6) on table A but fail to delete records (5,6) on table B, the script will fail to restore the constraint between Table A and B because now B has FK's (5,6) as orphans. The issue can be many things but I will start to look into the orphan issue First. Can you send the DDL of the tables? or a similar DDL I just want to see the kind of constraint between the tables.

  • Jorge,

    This is great stuff!

    However, it seems as though the restore portion does not correctly restore relationships that are based on more than one column.

    I think there needs to be a loop in the dynamic sql section that will iterate through the values in the sysforeignkeys.keyno field. You capture that data in the first part, but do not appear to use it in the restore process.

    If I am incorrect, my sincerest apologies. I ask only because I would hate to lose the multi-column FK relationships on my databases!


  • Thanks for the script.

  • ...still a bit scary.

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply