Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do foreign keys have size?

I am calculating a database size and I had one doubt about foreign keys. Do they have size? If they are references, do they occupy two different positions in memory?

like image 324
Fernando Mello Avatar asked Oct 17 '25 03:10

Fernando Mello


1 Answers

The columns that make up the foreign key do, of course, have size, but they would occupy the same amount of space whether or not they are participating in any foreign key relationship.

Most database products require that the target column(s) of a foreign key reference by indexed - but, again, such an index can exist even in the absence of a foreign key relationship.

Thirdly, the foreign key will require a small (fixed) amount of metadata to record its existence.

Beyond that, there may be some database products that do require some additional space to implement some foreign key features, such as cascading deletes. Such details would be product specific.

But in general, for plain foreign keys, there should be no additional storage requirement.

like image 192
Damien_The_Unbeliever Avatar answered Oct 19 '25 23:10

Damien_The_Unbeliever



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!