I have (all InnoDB) a parent table tbl1
with primary key some_id
and child (referencing) table tbl2
with another_id
referencing tbl1.some_id
as foreign key. tbl2.another_id
is not the primary key of tbl2
as this is a one to many relationship. Should my child table also have a primary key - maybe for indexing purposes?
The thread here almost answered my question but raised more questions about composite keys so I posted another question about that elsewhere...
Yes, you need to have a primary key on tbl2
. This will allow you to uniquely identify each row which will be useful for many purposes in the future. You can read up on the importance of keys with a google search.