After you create the tables, you can put data into them. You can insert data
manually with the INSERT statement, which uses the following syntax:
Click here to view code image
INSERT INTO table_name VALUES('value1', 'value2', 'value3', ...);
This statement inserts value1, value2, and so on into the table table_name.
The values that are inserted constitute one row, or record, in the database.
Unless specified otherwise, values are inserted in the order in which the
columns are listed in the database table. If, for some reason, you want to
insert values in a different order (or if you want to insert only a few values
and they are not in sequential order), you can specify which columns you
want the data to go in by using the following syntax:
Click here to view code image
INSERT INTO table_name (column1,column4) VALUES('value1', 'value2');
You can also fill multiple rows with a single INSERT statement, using syntax
such as the following:
Click here to view code image
INSERT INTO table_name VALUES('value1', 'value2'),('value3',
'value4');
In this statement, value1 and value2 are inserted into the first row, and value3
and value4 are inserted into the second row.
The following example shows how you insert the Nevermind entry into the
cd_collection table:
Click here to view code image
INSERT INTO cd_collection VALUES(9, 'Nevermind', 'Nirvana', '1991',
NULL);
MySQL requires the NULL value for the last column (rating) if you do not
want to include a rating. PostgreSQL, in contrast, lets you get away with just
omitting the last column. Of course, if you had columns in the middle that
were null, you would need to explicitly state NULL in the INSERT statement.
Normally, INSERT statements are coded into a front-end program, so users
adding data to the database do not have to worry about the SQL statements
involved.
Retrieving Data from a Database
Of course, the main reason for storing data in a database is so you can later