Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

tsql script check existing data on creation Expand / Collapse
Author
Message
Posted Monday, October 7, 2013 3:55 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Thursday, November 13, 2014 1:27 PM
Points: 425, Visits: 617
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?
Post #1502399
Posted Tuesday, October 8, 2013 4:24 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 12:12 AM
Points: 1,953, Visits: 2,397
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/
Post #1502535
Posted Tuesday, October 8, 2013 7:16 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Thursday, November 13, 2014 1:27 PM
Points: 425, Visits: 617
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
Post #1502596
Posted Thursday, October 10, 2013 1:44 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Thursday, November 13, 2014 1:27 PM
Points: 425, Visits: 617
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
Post #1503772
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse