May 18, 2003 at 11:10 pm
please refer TSQL forum.
Edited by - Dinesh on 05/18/2003 11:46:40 PM
May 18, 2003 at 11:56 pm
CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 INT )
CREATE TABLE t2 (c1 INT PRIMARY KEY, c2 INT )
ALTER TABLE t1 ADD CONSTRAINT t1t2FK FOREIGN KEY (c2) REFERENCES t2(c1)
ALTER TABLE t2 ADD CONSTRAINT t2t1FK FOREIGN KEY (c2) REFERENCES t1(c1)
INSERT INTO t1 VALUES ( 1, NULL )
INSERT INTO t2 VALUES ( 6, 1)
UPDATE t1 SET c2 = 6 WHERE c1 = 1
ALTER TABLE t1 NOCHECK CONSTRAINT t1t2FK
ALTER TABLE t2 NOCHECK CONSTRAINT t2t1FK
INSERT INTO t1 VALUES (2,3)
INSERT INTO t2 VALUES (3,2)
ALTER TABLE t1 CHECK CONSTRAINT t1t2FK
ALTER TABLE t2 CHECK CONSTRAINT t2t1FK
SELECT * FROM t1
SELECT * FROM t2
ALTER TABLE t1 DROP CONSTRAINT t1t2FK
ALTER TABLE t2 DROP CONSTRAINT t2t1FK
DROP TABLE t1
DROP TABLE t2
May 19, 2003 at 4:26 am
Please do not crosspost. See additional comments in http://www.sqlservercentral.com/forum/topic.asp?TOPIC_ID=12301&FORUM_ID=8&CAT_ID=1&Topic_Title=Mutually+dependent+foreign+key+constraints&Forum_Title=T%2DSQL
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply