Working with data: About Tables and Columns

  1. Choose database
  2. Working with data
  3. Create a table

All of your data in MySQL is stored in tables. When you view tables, they look a lot like spreadsheets. Each table consists of rows and columns. A row is one record; it is one set of data. A column is a field: it is one piece of data that each record has.

For example, if you are keeping a database of your record albums, you will have a row for Alice Cooper’s “Brutal Planet”. You will have a column for the artist’s name (“Alice Cooper”) and the album name (“Brutal Planet”).

Basic field types

In MySQL, you must specify what kind of data will go into columns. The two field types you’ll use most often are probably varchar and int. These are strings or text, and numbers. The title of an album and the artist is an example of text. If you also keep track of the year that the album came out, this is a number.

With varchar, you need to specify the maximum size of the text. If you specify a size that is too low, extra text will be truncated. You can always go back and change your mind, however.

About Tables and Columns: Dates

Dates are another common field type. You will enter dates as Year-Month-Day. For example, you might keep track of the day you purchased each album. If you bought Brutal Planet on January 3, 2005, you would enter this into your MySQL date column as 2005-1-3.

  1. Choose database
  2. Working with data
  3. Create a table