annotate tests/cst.ur @ 712:915ec60592d4

More flexible foreign keying
author Adam Chlipala <adamc@hcoop.net>
date Thu, 09 Apr 2009 13:59:34 -0400
parents 0406e9cccb72
children baaae037e7f6
rev   line source
adamc@712 1 table u : {C : int, D : int, E : option int}
adamc@709 2 PRIMARY KEY C,
adamc@712 3 CONSTRAINT U UNIQUE (C, D),
adamc@712 4 CONSTRAINT U2 UNIQUE E
adamc@709 5
adamc@712 6 table t : {A : int, B : int, C : option int}
adamc@707 7 PRIMARY KEY B,
adamc@707 8
adamc@704 9 CONSTRAINT UniA UNIQUE A,
adamc@704 10 CONSTRAINT UniB UNIQUE B,
adamc@704 11 CONSTRAINT UniBoth UNIQUE (A, B),
adamc@704 12
adamc@704 13 CONSTRAINT UniAm UNIQUE {#A},
adamc@705 14 CONSTRAINT UniAm2 {unique [#A] [[]] ! !},
adamc@705 15 {{one_constraint [#UniAm3] (unique [#A] [[]] ! !)}},
adamc@705 16
adamc@705 17 CONSTRAINT UniBothm UNIQUE ({#A}, {#B}),
adamc@705 18 CONSTRAINT UniBothm2 {unique [#A] [[B = _]] ! !},
adamc@709 19 {{one_constraint [#UniBothm3] (unique [#A] [[B = _]] ! !)}},
adamc@709 20
adamc@709 21 CONSTRAINT ForA FOREIGN KEY A REFERENCES u (C),
adamc@709 22 CONSTRAINT ForAB FOREIGN KEY (A, B) REFERENCES u (D, C) ON DELETE CASCADE ON UPDATE RESTRICT,
adamc@709 23 CONSTRAINT ForBA FOREIGN KEY (A, B) REFERENCES u (C, D) ON UPDATE NO ACTION,
adamc@712 24 CONSTRAINT ForB FOREIGN KEY B REFERENCES u (E),
adamc@712 25 CONSTRAINT ForC FOREIGN KEY C REFERENCES u (C)
adamc@709 26
adamc@712 27 (*CONSTRAINT Self FOREIGN KEY B REFERENCES t (B)*)
adamc@709 28
adamc@709 29 table s : {B : option int}
adamc@709 30 CONSTRAINT UniB UNIQUE B
adamc@709 31
adamc@709 32 table s2 : {B : option int}
adamc@709 33 CONSTRAINT ForB FOREIGN KEY B REFERENCES s (B) ON DELETE SET NULL
adamc@704 34
adamc@704 35 fun main () : transaction page =
adamc@704 36 queryI (SELECT * FROM t) (fn _ => return ());
adamc@704 37 return <xml/>