Loading Sample Gifts

Earlier in Editing the List of Gifts,” we saw how the administrator can manually add gifts to the database. You can, of course, add gifts by running SQL INSERT queries using the MySQL monitor. For example, you can type:

mysql> INSERT INTO gifts VALUES
    -> (NULL,'Acme 48-piece dinner set','SomeShop',1,'White','102.10',NULL);

Specifying a NULL value for the first field, gift_id, lets the MySQL server automatically assign an auto-incremented ID; the first gift inserted into the table will have a gift_id of 1, the next one will have a gift_id of 2, and so on.

We also specify a NULL value for the last field, username, since gifts newly loaded in the database are not reserved by any user. When a user reserves a gift, her username is stored in the username field for that gift.

To help save you some typing, we’ve generated a few sample gifts that you can load into your database by running the SQL queries in the populate_wedding_database.sql file that you can download from the book’s home page:

$ mysql --user=fred --password=shhh < populate_wedding_database.sql

Note that this file includes the statement:

DELETE FROM gifts;

to first delete any existing gift entries from the database.

Get Learning MySQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.