tsql script check existing data on creation

  • I am missing something here. I need to create a script to do this.

    To disable I do the following command

    EXECUTE sp_msforeachtable @command1="Print 'Test'", @Command2 ="ALTER TABLE Foo.tblFoo NOCHECK CONSTRAINT all"

    To enable the FK I do this

    EXECUTE sp_msforeachtable @command1="Print 'Test'", @Command2 ="ALTER TABLE Foo.tblFoo CHECK CONSTRAINT all"

    The check existing data on creation in the table is still set to "No". I can't seem to google a solution. Any of you potentially know if this can be done without using the ui?

  • EXECUTE sp_msforeachtable @command1="Print 'Test'", @Command2 ="ALTER TABLE Foo.tblFoo CHECK CHECK CONSTRAINT all"

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • I did find that one in searching

    EXECUTE sp_msforeachtable @command1="Print 'Test'", @Command2 ="ALTER TABLE Foo.tblFoo WITH CHECK CHECK CONSTRAINT all"

    Am I doing something incorrectly because it seems to have no effect on the FK

  • Hey sorry about the confusion. I must have been doing something differently that was not working. I tried this again today and it worked. Thanks

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

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