Database Reference
In-Depth Information
5
Populating the Database
INSERT
The main method of putting data into our table is by using the SQL INSERT command. The
most commonly used format of this command is as follows:
INSERT
INTO tablename (columnname, columnname, …)
VALUES (value, value, …);
The insert command adds a new record to the table, putting the date given into the fields
specified. You must ensure that all of the column names specified after the tablename have
corresponding entries in the VALUES section. The values must be of the same datatype as
the column they are going to be inserted into.
Any columns that are not specified in the statement are left at their default value if you
specified it, or set to NULL.
To demonstrate, we will begin to add some data into the database that we described earlier. To
start with we will add data to the webpage table, which will store the title and content of our web-
site. All websites have a home page so we will start by inserting a home page. Start up the graphical
tools and log in. Type the following to ensure that we are connected to the correct database:
USE MySQLfast
You can also ensure that you are connected to the MySQLfast database by checking that the
client says MySQLfast next to the word Connected on the second row of controls on the
client. If it says mysql you are in the wrong database, so pull down the menu by clicking on
the square next to mysql and select MySQLfast . Once you are connected to the correct data-
base you can type the following in the query box:
INSERT
INTO webpage (Title)
VALUES (“Home”)
Click onto the Execute Query button to run the query. Unless there is an error there will
not be any output to show you what you have just done. If you do have an error message it
is likely that you have not connected to the database, or you have not yet created the web-
page table as described in the previous chapter. If the latter is the case, please review the
create table section in Chapter 4.
45
Search WWH ::




Custom Search