The theme for the sample tables is a grocery store, with departments and items. Of course an information system for a real grocery store would contain many more tables describing employees, suppliers, and sales but two tables will suffice for our purpose.
We suppose here that your MySQL username is
sarah and that this account is allowed to create databases with the prefix
A MySQL database is a container for tables. The new database will be named
sarah_grocery, assuming that the system administrator enforces the policy that all databases must have the username as a prefix. The rest of the database name consists of the project name, which here is
Log in to MySQL via phpMyadmin's login panel, with the username sarah.
Click on the Databases menu tab.
Change the database name from sarah_.... to sarah_grocery.
Click on the Create button.
You must now tell phpMyAdmin to use sarah_grocery as the current database. This way, all actions will take place in the context of this database. The easiest way to open it is by clicking on the database name from the navigation panel (which is located on the left-hand side if you are using a left-to-right language like English).
Now that you have a database to play with, it's time to create a table that will hold the description of the grocery's departments. To be able to create inter-table relations in a later task without the need for installing further phpMyAdmin elements, all the tables in this exercise will use the InnoDB storage engine—see http://www.innodb.com and http://dev.mysql.com/doc/refman/5.5/en/innodb-storage-engine.html.
When opening a database, you are by default in its Structure page where you can see existing tables and views belonging to this database. You now use the Create table initial dialog to specify the table name and initial number of columns:
Clicking on Go brings up the columns panel where you'll create two columns,
id (an integer column) and
description (a variable-size character column having a maximum length of 100). The
id column is marked as being the primary key.
Scrolling to the bottom of this panel and clicking Save creates the table. You now see a different Structure panel, which shows the existing table, department, on which you can apply actions, and the Create table dialog to create further tables.
id (an integer and primary key)
dept_id (an integer)
description (VARCHAR 100)
weight (an integer)
You will notice that both tables have a column
id as the primary key; however, there is no risk of confusion because SQL requires using the table name in queries, such as the following:
SELECT id FROM item
In the current step you'll use the Insert menu, which can be reached from the database Structure page. Let's begin by inserting new departments; on the line for the department table, click on Insert, which brings the insertion panel. Then enter this sample data:
INSERT INTO `sarah_grocery`.`department` (`id` ,`description` ) VALUES ( '1', 'Baby foods' ), ( '2', 'Frozen foods' );