Inserting data

Now that you are able to create, alter, and delete tables at will, we can continue on by looking at how to insert data into our test table. Make sure you have the phpdb database and the original usertable table (that is, with Age and without MiddleName) created before continuing.

To insert data into your table, you use the "INSERT INTO" SQL command:

INSERT INTO usertable VALUES (1, "Jack", "Black", 29);

The INSERT INTO command above tells your database that you would like your data placed into the specified table - usertable, in the example. The data in between the brackets themselves is what goes into your fields, and it should match with the table definition precisely. As usertable had the fields ID INT, FirstName CHAR(255), LastName CHAR(255), and Age INT, the values we're entering are ID 1, FirstName "Jack", LastName "Black", and "Age 29. Note that the character data must be surrounded by quotes (either single or double).

We'll be looking at more advanced data insertion later - for now, it is just important to learn the basics.

 

Next chapter: Selecting data >>

Previous chapter: Deleting tables

Jump to:

 

Home: Table of Contents

Follow us on Identi.ca or Twitter

Username:   Password:
Create Account | About TuxRadar