How to Insert Data Into a MySQL Table

by austingulati on January 26, 2011

  • Share
  • CevherShare
  • Share

Now that you’ve got your MySQL database set up, it’s time to start inserting data into the MySQL tables.

The query that has to be run in order to insert data is called an INSERT query. The syntax is basically as follows:

INSERT INTO table_name (table_column, ...) VALUES (value, ...)

The first parameter is self-explanatory: table_name is the name of the table that you are inserting into. The next two parts are a little more complicated, though.

The (table_column, ...) part isn’t required, actually. If you don’t include this, it assumes that you will be providing values for all of the columns of the table. Otherwise, the list of columns that you provide here corresponds with the values that you provide in the next section. All of the values should be properly quoted. Numeric values and other non-string values don’t have to be quoted, but usually you can quote them anyway. It’s usually better to be safe than sorry.

That’s pretty much all that you need to know about MySQL insertion. Inserting into a table is fairly simple compared to selecting from a table or other more complicated queries.

Leave a Comment

Previous post:

Next post: