What is the foreign key (SQL) for

Asked

Viewed 462 times

4

For what I’ve been researching, when pulling the information of two tables in a database, JOIN is used, which has nothing to do with foreign key.

So what’s the point of declaring a field as Foreign key (foreign key)? I don’t see the point. Someone please explain it to me?

  • Data integrity!

1 answer

1


Declaring a field as a foreign key specifies which field connects the two tables in Join, both for those who produce querys for it, and for the bank itself to handle the optimization.

One of the main points of standardization in a database is to guarantee their integrity by declaring a foreign key, you ensure that that relationship will happen whenever possible, not filling the table with non-existent values in the other.

Foreign key

A foreign key is called when there is the 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 Junction

Database table are similar to number sets and sometimes we need to find the intersection between them, as you can see below:

inserir a descrição da imagem aqui

These tables are linked by a common field between them, these field must be the foreign key they enter.

Normalization of Relational Databases

Normalization is a process from which rules apply to all tables in the database in order to avoid project failures, such as data redundancy and mixing of different subjects in the same table.

Read More

Browser other questions tagged

You are not signed in. Login or sign up in order to post.