1

定義をREFERENCES拡張してテーブル制約もサポートできず、 FOREIGN KEYSQLから削除できなかったのはなぜですか?

REFERENCESとの違いは、列の制約であるのに対し、テーブルの制約であるFOREIGN KEYことは明らかです。REFERENCESFOREIGN KEY

たとえば、制約が複数の列を参照しているため、の前create table T (A int, B int, C int, primary key (A,B), (B,C) references T(A,B) on delete cascade)に持っている必要があるため、は合法ではありません。foreign key(B, C)

4

1 に答える 1

1

SQL は冗長で非常に明示的です。なんで?SQL-1992 標準がすでに次のように定義しているという事実を除いて、良い答えはありません。

11.8 <referential constraint definition>

[...]

Format

     <referential constraint definition> ::=
          FOREIGN KEY <left paren> <referencing columns> <right paren>
            <references specification>

     <references specification> ::=
          REFERENCES <referenced table and columns>
            [ MATCH <match type> ]
            [ <referential triggered action> ]

FOREIGN KEYは、DDL ステートメントの必須キーワードです。それでおしまい。制約はor制約FOREIGN KEYと比較して上位クラスの市民であってはならないと主張することができます。したがって、それらはすべて適切なキーワードが必要です。UNIQUECHECK

11.6 <table constraint definition>

[...]

    <table constraint> ::=
            <unique constraint definition>
          | <referential constraint definition>
          | <check constraint definition>
于 2012-08-14T14:51:38.450 に答える