MySQL Forums
Forum List  »  Newbie

Re: Primary key in table
Posted by: Phillip Ward
Date: September 19, 2017 05:08AM

Quote

My question is this primary key field necessary for the table.

Is a primary key required for a table? Yes. Absolutely.

Is this "surrogate" primary key required? No.

If your table has a Natural Key made of you of combinations of data fields, then there's noting to stop you defining that as the primary key. Indeed, I would argue that this is a better idea because,when things go wrong, you can "see" what's going on in the database without loads of meaningless numbers getting in the way.

Quote

... if we have an employee table the employee has a social security number that is unique and would seem to be a good primary key so why should I create another field to be the primary key ...

You're quite right but your choice of primary key has to be carefully made.

Ideally a Primary Key [value] should be assigned when a record is first created and should never change until the record is finally destroyed (and, preferably, never reused thereafter; this is why sequential numbers seem so attractive). In extreme circumstances, Social Security Number can change, so perhaps not the best choice of key (which is why Name would be a poor choice as well).

Regards, Phill W.

Options: ReplyQuote


Subject
Written By
Posted
September 16, 2017 10:22AM
September 16, 2017 01:44PM
September 16, 2017 02:40PM
September 16, 2017 02:56PM
Re: Primary key in table
September 19, 2017 05:08AM
September 20, 2017 11:29AM
September 20, 2017 12:20PM
September 20, 2017 12:42PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.