content_image/696240.jpg
The pet  table keeps track of which pets you have. If you want to record other information about them, such as events in their lives like visits to the vet or when litters are born, you need another table. What should this table look like? It needs to contain the following information: 

•The pet name so that you know which animal each event pertains to. 

•A date so that you know when the event occurred. 

•A field to describe the event. 

•An event type field, if you want to be able to categorize events. 

Given these considerations, the CREATE TABLE  statement for the event  table might look like this: 

mysql> CREATE TABLE event (name VARCHAR(20), date DATE, type VARCHAR(15), remark VARCHAR(255)); 

As with the pet  table, it is easiest to load the initial records by creating a tab-delimited text file containing the following information. 

<img src='content_image/696240.jpg'>

Load the records like this: 

mysql> LOAD DATA LOCAL INFILE ’event.txt’ INTO TABLE event; 

Based on what you have learned from the queries that you have run on the pet  table, you should be able to perform retrievals on the records in the event  table; the principles are the same. But when is the event table by itself insufficient to answer questions you might ask? 

Suppose that you want to find out the ages at which each pet had its litters. We saw earlier how to calculate ages from two dates. The litter date of the mother is in the event  table, but to calculate her age on that date you need her birth date, which is stored in the pet  table. This means the query requires both tables: 

mysql> SELECT pet.name, TIMESTAMPDIFF(YEAR,birth,date) AS age, remark 

