How to Insert Data Into a MySQL Table

Last Updated on: January 26, 2011

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:

{code type=”sql”}INSERT INTO table_name (table_column, …) VALUES (value, …){/code}

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.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *