Table creation rules of thumb


Part I: MySQL tutorial
Part II: PHP tutorial

Start:



Links:
MySQL Manual
PHP Manual
Student Server Home

Things to bear in mind when designing a table:

  • Think ahead! When you're first designing a table, it's very easy to change its structure. But when you've got 40,000 lines of code dealing with that database, you don't want to look through them all and make the changes necessary because you realized you needed an extra column.
  • Primary keys: each table should have a primary key, which is usually one column (although it can be several) that is designated as always unique -- a sort of index for the table, if you will. The database can do very fast searching on this column, so it's highly useful. The easiest way to make a primary key is to add an "id" column that numbers each row from 1 to n. (We'll talk about how to do that shortly.)
  • Avoid numeric types. Each column has to have a type -- a kind of data that it accepts. This might be a date, an integer, or a string (any sequence of numbers, characters, etc.). If you don't plan on using the data in a column to do math, don't use a numeric type, even if you expect all the data to be numeric.

With that said, let's create our first table!