Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use primary keys?

What are primary keys used aside from identifying a unique column in a table? Couldn't this be done by simply using an autoincrement constraint on a column? I understand that PK and FK are used to relate different tables, but can't this be done by just using join?

Basically what is the database doing to improve performance when joining using primary keys?

like image 932
kln Avatar asked Dec 23 '22 06:12

kln


1 Answers

Mostly for referential integrity with foreign keys,, When you have a PK it will also create an index behind the scenes and this way you don't need table scans when looking up values

like image 194
SQLMenace Avatar answered Dec 28 '22 05:12

SQLMenace