Quick question about mySQL primary key indexy thingy wotsit
#1

Can someone explain the primary key or index or whatever stuff in mySQL really briefly? Is it required?
Reply
#2

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)