I have a question about creating a simple database. Here are the 2 tables.
They are linked by the primary/foreign key 'client_id'. I think that I
understand that part.
I have 'KEY birthdate(birth date)' in the clients table definition. I'm not
sure when I should have that. When is it desirable to use the 'KEY' in the
definition? If I wanted to be able to often and quickly sort the clients table
by lastname, firstname, or birthdate, should I use the 'key' phrase? Ie, would
the clients table sort faster on birthdate than on lastname in this example?
If I wanted to be able to efficiently sort on all columns then should I have a
'key' phrase for each column in the table?
CREATE table clients (
client_id int(10) unsigned NOT NULL auto_increment,
birthdate date NOT NULL default '0000-00-00',
lastname char(15) NOT NULL,
firstname char(15) NOT NULL,
PRIMARY KEY (client_id),
KEY birthdate(birth date)
);
CREATE table sales (
saleno int(10) unsigned NOT NULL auto_increment,
client_id int(10) unsigned NOT NULL,
description char(15) not null,
amount float(10,2) NOT NULL,
PRIMARY KEY (saleno),
KEY amount(amount),
constraint foreign key (client_id) references clients (client_id)
);
thanks,
Jim
Comment