Referential Integrity check (without foreign key defined)

  • Hi,

    I must execute a referential Integrity check on DBs. No FK has been defined on those DBs. Only PK exist on those BDs. Does anyone can suggest me some tools, scripts, strategies that will help me ?

    Thank you

    Danny

     

  • What you (they) did not put into it, you'll not get out of it the easy way

    Lest's hope you have naming-conventions to point to related stuff.

    If you have, you might be able to generate scripts from related to parent table to filter the non-existing FK.

    select *

    from dependant_table D

    where not exists (select *

                               from parent_table 

                             where pk = D.fk_parent_table_column(s) )

    I hope this gets you on track ..

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • Well, without foreign keys I'd say you don't have any referential integrity to check.  I assume your RI is enforced by appliction code.

    I'd say your options are to check your RI programatically either with actual application code or with Select statements.  Or you could create the foreign keys that your programs enforce and thereby let SQL Server check your RI. 

Viewing 3 posts - 1 through 2 (of 2 total)

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