Insert data ignoring Foreign Key Constrain

  • How I can Insert data into sqlserver table ignoring Foreign Key Constrain




    My Blog: http://dineshasanka.spaces.live.com/

  • take a look at BOL : search for "NOCHECK CONSTRAINT"

    alter table myschema.mytable NOCHECK CONSTRAINT myconstraint

     

    don't forget to enable it again when you're done.

    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

  • Thankx

    I couldn't find it earlier

    thankx again

     




    My Blog: http://dineshasanka.spaces.live.com/

  • You can use one of these

    --- disable all constrains

    sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"

    --- disable all triggers

    sp_msforeachtable "ALTER TABLE ? DISABLE TRIGGER all"

    and then... as told you alzdba, remember to re-enable them...

    --- enable alla constrains

    sp_msforeachtable @command1="print '?'",

       @command2="ALTER TABLE ? CHECK CONSTRAINT all"

    --- enable all triggers

    sp_msforeachtable @command1="print '?'",

       @command2="ALTER TABLE ? ENABLE TRIGGER  all"

    Bye, Chiara

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

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