Inserting Data into a Table
Our database is created and our table is built; all that's left is toput some actual jokes into our database. The command for inserting data into
our database is called, appropriately enough, INSERT. There
are two basic forms of this command:
mysql>INSERT INTO table_name SET
-> columnName1 = value1,
-> columnName2 = value2,
-> ...
->;
mysql>INSERT INTO table_name
-> (columnName1, columnName2, ...)
-> VALUES (value1, value2, ...);
So, to add a joke to our table, we can choose from either of these commands:
mysql>INSERT INTO Jokes SET
->JokeText = "Why did the chicken cross the road? To get to
"> the other side!",
->JokeDate = "2000-04-01";
mysql>INSERT INTO Jokes
->(JokeText, JokeDate) VALUES (
->"Why did the chicken cross the road? To get to the other
"> side!",
->"2000-04-01"
->);
Note that in the second form of the INSERT command,
the order in which you list the columns must match the order in which you
list the values. Otherwise, the order of the columns doesn't matter, as long
as you give values for all required fields. Now that you know how to add entries
to a table, let's see how we can view those entries.