Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有以下两张表。
CREATE TABLE parent ( c1 INTEGER ); CREATE TABLE child ( c1 INTEGER, c2 INTEGER, c3 INTEGER, CONSTRAINT fk_c3 FOREIGN KEY(c3) REFERENCES parent(c1) );
您一定已经注意到该列c1不是 Parent 表中的主键。有没有办法在不c1作为主键的情况下在子表中引用它?
c1
有没有办法在不将'c1'作为主键的情况下在子表中引用它?
是的。外键只需要引用一个唯一约束——它不必是主键。您可以在该列上创建一个独特的约束。