SA-MP Forums Archive
Quick question about mySQL primary key indexy thingy wotsit - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Other (https://sampforum.blast.hk/forumdisplay.php?fid=7)
+--- Forum: Everything and Nothing (https://sampforum.blast.hk/forumdisplay.php?fid=23)
+--- Thread: Quick question about mySQL primary key indexy thingy wotsit (/showthread.php?tid=348337)



Quick question about mySQL primary key indexy thingy wotsit - MP2 - 05.06.2012

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


Re: Quick question about mySQL primary key indexy thingy wotsit - pyrodave - 05.06.2012

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.