Archive for the 'Insert Into' Category

Inserting Data into SQL Tables

Inserting data into a database is essential especially if we have a dynamic site. Data can be inserted into an existing table using INSERT INTO query.

INSERT INTO tableName VALUES (value,value);

Let’s see an example of INSERT INTO in action, remember the table we created, let’s continue where we left off.

In our SQL form, we are going to type in:

INSERT INTO names VALUES
(
‘NULL’,'Tom Cruise’
)

now remember we had two fields, id and name. What this query does is insert “Tom Cruise” into the name field , but notice the NULL, that is so it ignores the first field which is our primary key and is on auto_incremement. To get a glimpse of what our database is starting to look like, let’s see its layout.

In your SQL interface, let’s type in:

SELECT * FROM names;

You should see a 1 under id and Tom Cruise under the name column

Now obviously for any database of substantial size, we are going to need some quicker way of inserting information, or how about automated? Like when someone enters information on a form, all that goes into a database.