Posts: 6,236
Threads: 310
Joined: Jan 2011
Reputation:
0
Can someone explain the primary key or index or whatever stuff in mySQL really briefly? Is it required?
Posts: 117
Threads: 8
Joined: Jul 2008
Reputation:
0
A good primary key will be something you most often use to select from in your database, as primary keys are kept indexed by the database engine. For example, when building a user database for your players, you would probably want to use the players name as a primary key, so you cant have people registering with the same name more than once, and because when a player joins you're selecting data based on their name.
You can also use compound keys if you don't have a single database attribute which is truly unique but you do have two (or more), attributes which you want to use to identify a record.
If you do not have some sort of key, the database may lack in performance, and all sorts of problems may arise. If you're confused as what to use for a primary key, you can create an ID field using an auto incrementing integer which will serve the purpose. But ideally you want to pick a suitable key based on the attributes you have, your database requirements and your select habits.