By default, referenced columns must be in the same database as the referencing foreign key column.In these cases, the FOREIGN KEY constraint and the referenced table's primary key must contain the same number of columns. In the REFERENCES clause, if you specify a table but no columns, CockroachDB references the table's primary key.The order of the columns in the foreign key definition does not need to match the order of the columns in the corresponding UNIQUE or PRIMARY KEY constraint. For example, the clause REFERENCES tbl (C, D) requires tbl to have either the constraint UNIQUE (C, D) or PRIMARY KEY (C, D). This means the REFERENCES clause must use exactly the same columns as a UNIQUE or PRIMARY KEY constraint on the referenced table. Referenced columns must contain only unique sets of values.This applies to whichever column is used as the partitioning column, in case a different name is used via REGIONAL BY ROW AS. This is possible because crdb_region is implicitly included in every index on REGIONAL BY ROW tables as the partitioning key. A foreign key column can reference the crdb_region column in REGIONAL BY ROW tables even if the crdb_region column is not explicitly part of a UNIQUE constraint.For an example, see Add multiple foreign key constraints to a single column. A single column can have multiple foreign key constraints.A foreign key column cannot be a virtual computed column, but it can be a stored computed column.Foreign key columns must use their referenced column's type.To read more about how foreign keys work, see our What is a Foreign Key? (With SQL Examples) blog post.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |