![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
You can define FK on tables on simply disable them for loading maintainance or other purposes, and then enable them again. Otherwise you would have to drop them and recreate them. CREATE TABLE SomeParentTable ( ParentPKCol INT CONSTRAINT PK_SomeParentTable PRIMARY KEY (ParentPKCol) ) Create table SomeChildTable ( PKChildCol INT, ParentPKCol INT NOT NULL CONSTRAINT fk1_SomeParentTable FOREIGN KEY REFERENCES SomeParentTable (ParentPKCol) ) --Doesn´t work, CHECK is enabled insert into SomeChildTable Values (1,1) --Disabling the CHECK ALTER TABLE SomeChildTable NOCHECK CONSTRAINT fk1_SomeParentTable --This works now insert into SomeChildTable Values (1,1) --Delete it once again DELETE FROM SomeChildTable --THis is the normal behaviour ALTER TABLE SomeChildTable NOCHECK CONSTRAINT fk1_SomeParentTable --Inserting first the parent then the child records insert into SomeParentTable Values (1) insert into SomeChildTable Values (1,1) Drop table SomeChildTable Drop table SomeParentTable HTH, Jens Suessmeyer. |
![]() |
| Thread Tools | |
| Display Modes | |
| |