As I've been researching, when it comes to pulling information from two tables in a database, you use JOIN, which has nothing foreign key in it.
So what's the use of declaring a field as a foreign key? I see no point. Can someone explain me please?
As I've been researching, when it comes to pulling information from two tables in a database, you use JOIN, which has nothing foreign key in it.
So what's the use of declaring a field as a foreign key? I see no point. Can someone explain me please?
Declaring a field as a foreign key explicitly specifies the field that binds the two tables in the join, both for whom it will produce queries for it and for the database itself to handle the optimization.
One of the key points of normalizing a database is to ensure their integrity by declaring a foreign key, you make sure that that relationship will happen whenever possible, not filling the table with missing values in the other
Foreign Key
A foreign key is called when there is a relationship between two tables.
Always in foreign key there will be relationships between tables, for example, if a table that has a primary key from another table.
Table Join
Database table are similar to number sets and sometimes we need to find the intersection between them, as you can see below:
Thesetablesareboundbyacommonfieldbetweenthem,thesefieldshouldbetheforeignkeyenteringthem.
RelationalDatabaseNormalization
Normalizationisaprocessfromwhichrulesareappliedtoalldatabasetablesinordertoavoidprojectfailures,suchasdataredundancyandmixingofdifferentsubjectsinthesametable.
Read More