![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
Hi Shimon, Welcome to use MSDN Managed Newsgroup! You could use NOCHECK instead of UNCHECKED when altering a existing constraint to be invalid. I made a sample on my side with DTS and it works. Here is a sample CREATE TABLE Test2 ( TID INT Primary KEY, CID INT IDENTITY(1,1) UNIQUE ) INSERT Test2 VALUES (11) INSERT Test2 VALUES (12) INSERT Test2 VALUES (13) INSERT Test2 VALUES (14) --SELECT * FROM Test2 CREATE TABLE Test2Child ( TCID INT FOREIGN KEY REFERENCES Test2(CID), TC CHAR(1) ) INSERT Test2Child VALUES (55,'B') --The statement above will fail ALTER TABLE Test2Child NOCHECK CONSTRAINT FK__Test2Child__TCID__48CFD27E INSERT Test2Child VALUES (55,'B') --The statement above will do since we have altered NOCHECK --Use a DTS package to do the test, it also works NOTE that if you have specified NOCHECK for the constraint, it will not check the constraints any more. Sincerely yours, Michael Cheng Microsoft Online Partner Support When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== === This posting is provided "AS IS" with no warranties, and confers no rights. |
#4
| |||
| |||
|
|
Michael Do you suggest me to write the script for each table to disable keys? It is not really a solution since I have over 100 tables. Plus the schema changes and my script can become invalid. Is there something that can disable all the keys whatever they are? An if such thing exists how can I out it in the DTS package together with backup and data transfer tasks? Thank you, Shimon "Michael Cheng [MSFT]" <v-mingqc (AT) online (DOT) microsoft.com> wrote in message news:%2338TAel6FHA.3036 (AT) TK2MSFTNGXA02 (DOT) phx.gbl... Hi Shimon, Welcome to use MSDN Managed Newsgroup! You could use NOCHECK instead of UNCHECKED when altering a existing constraint to be invalid. I made a sample on my side with DTS and it works. Here is a sample CREATE TABLE Test2 ( TID INT Primary KEY, CID INT IDENTITY(1,1) UNIQUE ) INSERT Test2 VALUES (11) INSERT Test2 VALUES (12) INSERT Test2 VALUES (13) INSERT Test2 VALUES (14) --SELECT * FROM Test2 CREATE TABLE Test2Child ( TCID INT FOREIGN KEY REFERENCES Test2(CID), TC CHAR(1) ) INSERT Test2Child VALUES (55,'B') --The statement above will fail ALTER TABLE Test2Child NOCHECK CONSTRAINT FK__Test2Child__TCID__48CFD27E INSERT Test2Child VALUES (55,'B') --The statement above will do since we have altered NOCHECK --Use a DTS package to do the test, it also works NOTE that if you have specified NOCHECK for the constraint, it will not check the constraints any more. Sincerely yours, Michael Cheng Microsoft Online Partner Support When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== === This posting is provided "AS IS" with no warranties, and confers no rights. |
#5
| |||
| |||
|
|
You can create a task that will create a script (or even a Stored Proc) that will disable and then reenable the constraints. You can generate both scripts by the below resultset: SELECT 'ALTER TABLE ' + TABLE_NAME + ' NOCHECK CONSTRAINT ALL' FROM INFORMATION_SCHEMA.TABLES SELECT 'ALTER TABLE ' + TABLE_NAME + ' CHECK CONSTRAINT ALL' FROM INFORMATION_SCHEMA.TABLES Scott "Shimon Sim" <shimonsim048 (AT) community (DOT) nospam> wrote in message news:e$ma4qu6FHA.3752 (AT) tk2msftngp13 (DOT) phx.gbl... Michael Do you suggest me to write the script for each table to disable keys? It is not really a solution since I have over 100 tables. Plus the schema changes and my script can become invalid. Is there something that can disable all the keys whatever they are? An if such thing exists how can I out it in the DTS package together with backup and data transfer tasks? Thank you, Shimon "Michael Cheng [MSFT]" <v-mingqc (AT) online (DOT) microsoft.com> wrote in message news:%2338TAel6FHA.3036 (AT) TK2MSFTNGXA02 (DOT) phx.gbl... Hi Shimon, Welcome to use MSDN Managed Newsgroup! You could use NOCHECK instead of UNCHECKED when altering a existing constraint to be invalid. I made a sample on my side with DTS and it works. Here is a sample CREATE TABLE Test2 ( TID INT Primary KEY, CID INT IDENTITY(1,1) UNIQUE ) INSERT Test2 VALUES (11) INSERT Test2 VALUES (12) INSERT Test2 VALUES (13) INSERT Test2 VALUES (14) --SELECT * FROM Test2 CREATE TABLE Test2Child ( TCID INT FOREIGN KEY REFERENCES Test2(CID), TC CHAR(1) ) INSERT Test2Child VALUES (55,'B') --The statement above will fail ALTER TABLE Test2Child NOCHECK CONSTRAINT FK__Test2Child__TCID__48CFD27E INSERT Test2Child VALUES (55,'B') --The statement above will do since we have altered NOCHECK --Use a DTS package to do the test, it also works NOTE that if you have specified NOCHECK for the constraint, it will not check the constraints any more. Sincerely yours, Michael Cheng Microsoft Online Partner Support When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== === This posting is provided "AS IS" with no warranties, and confers no rights. |
![]() |
| Thread Tools | |
| Display Modes | |
| |