简体   繁体   中英

Apache Derby understanding differences between references and foreign key

I hava known that foreign key is a constraint and references is a clause.

This also confuse me.Although it is mysql but not apache derby

This tells me how foreign key work but still confused for me I found out the answer also has the command like what i said references without foreign key

But my question is what is the point if you can create table which having references column to the other table without using foreign key. the command below still work

create table newTable(ColumnName varchar(100) references oldTable(ColumnName))

the foreign key example at the bottom of this document use foreign key to make references

Can anyone please help me out that differences between using references with foreign key and not using foreign key

I found out in SQLite if you references without foreign key it is same as references with foreign key is apache derby run in same way?

A "foreign key" is the set of attributes of the referencing table. (In many implementations, one would have to speak of "ordered set of attributes" because many implementations make the order matter too, but that's a deviation from the theory.)

A referential integrity constraint is the rule as such to the effect that the [combination of] values appearing in the foreign key attributes [in the referencing table] must appear as [a combination of] values in the key attributes [in the referenced table]. ("key attributes" is a usage of the term "key" that is in line with relational theory. They might have been declared by means of a UNIQUE clause instead of a KEY clause, but that's just syntax. In the theory, everything that's declared unique is a key.)

The "REFERENCES" clause is the [most popular / most used] means to declare the referential integrity constraint. It's a syntactic means. It always includes a specification of the foreign key, but additionally it also defines the referenced table and its referenced attributes.

Because it is so exceptionally rare that there are two distinct referential integrity constraints based on the SAME foreign key (eg to two distinct referenced tables), it is quite common for all those terms to be used interchangeably.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM