Working with data 9
CocoaMySQL made an ID field for us, but it does not automatically increment by default.
Field Purpose
Field Name
Field Contains
MySQL Field Type
identifier
id
number
int
For our ID field, we must tell MySQL to auto increment the column. When we do this,
CocoaMySQL will tell us that auto increment fields need to be indexed; do we want to make
this our primary key? Click the okay button and CocoaMySQL will make an index for us.
We'll talk about indexes later.
If you are using the command line, use the following commands:
alter table albums add column id int unsigned not null auto_increment primary
key;
Import data
We have two sets of sample data. The one we're looking at right now is the albums.txt file.
This file is a tab delimited list of albums, artists, years, and date purchased.
In CocoaMySQL, pull down the File menu, go to the Import submenu, and choose
CSV file . Because different computers have different line endings, and because different
export options will use different things to separate fields, you need to tell CocoaMySQL that
fields are terminated by tabs ( \t ), that the fields are not enclosed by anything, and that the
first line does not contain field names.
Next, you'll need to choose which items in the file go to which field. One of the first things
you'll notice is that we have an extra field. This data contains what looks to be the format of
the album: if you scroll through the data you can see values of CD, Vinyl, or Cassette. We
aren't keeping track of that data, so choose Do not import .
Because CocoaMySQL does not let you import the same data into two different fields, you
will need to also use Do not import temporarily for one or two of the others.