Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

relational terminology: foreign key source, destination?

I'm doing some FK analysis of our tables by making a directed graph representing FK dependencies and then traversing the graph. In my code, I name everything using directed graph terminology, but I'd like to have something a bit more "user friendly" in the report.

In this scenario:

create table t1(a varchar2(20));
alter table t1 add constraint t1_fk foreign key(a) references t2(b);

t1.a must exist in t2.b. So, what words should I use in the blanks?

t1 is the _______ of t2.
t2 is the _______ of t1.

Many TIA!

like image 484
Mark Harrison Avatar asked Nov 03 '08 08:11

Mark Harrison


People also ask

What is a foreign key in a relational database?

A relational database is designed to enforce the uniqueness of primary keys by allowing only one row with a given primary key value in a table. Foreign keys. A foreign key is a column or a set of columns in a table whose values correspond to the values of the primary key in another table.

What do you mean by foreign key?

A foreign key is a column or columns of data in one table that connects to the primary key data in the original table.

What is the purpose of defining a foreign key in a relation?

Foreign keys put the “relational” in “relational database” – they help define the relationship between tables. They allow developers to maintain referential integrity across their database.

Can you reference a foreign key?

A foreign key can reference any field defined as unique. If that unique field is itself defined as a foreign key, it makes no difference. A foreign key is just to enforce referential integrity. Making a field a foreign key doesn't change the field itself in any way.


1 Answers

I'd say (things between brackets are optional, but I'd use them)

[Column a of] table t1 references [column b of] table t2

and

[Column b of] table t2 is referenced by [column a of] table t1

?

I'd also specify the action that happens on delete/update if any.

Column b of table t2 is referenced by column a of table t1. 
Deleting a record in table t2 will delete matching records on table t1
like image 93
Vinko Vrsalovic Avatar answered Nov 15 '22 06:11

Vinko Vrsalovic