Programmer's Wiki

Visit phpMyAdmin in your web browser. Next to "Create new database," enter a name for your first database, then open the Collation drop-down menu, select utf8_general_ci, and click Create. Technically you now have a database, but we're far from done! You need to add tables to it, as all a database is good for is to group database tables together.

So select the name of your database on the left panel and think of a set of things your table should represent, like your favorite restaurants or the countries in the world. Don't create the table yet, but enter a name for it and the number of fields (columns) it will contain. A field is just a piece of information that is attached to every record (row) in a table, with the intersections of columns and rows being called values. You should add one to the number of details you need to record about a thing because each thing needs a unique number that refers to it, conventionally listed as the first field.

Click the "Go" button and enter a name for each field. By convention, the first should be named either "id" or "tablename_id" and is used to uniquely identify each record. Give it a type of UNSIGNED INT and the attribute PRIMARY KEY, then check the A_I box. This means that:

  • it's a number that's never negative (we don't need to use -413 just 413), or unsigned integer;
  • no two records can share the same id (primary keys are unique);
  • it's the most efficent criterium to use in searches because the table itself is ordered by it (because it's the *primary* key); and
  • we don't ever need to specify an id because each new record is automatically assigned with the lowest available one (the A_I checkbox indicates the field is to be auto-incremented).

[To be continued...]