DevChunks

How to Insert Data Into a MySQL Table

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.

Share:

Leave a Reply

Your email address will not be published.

More Posts

How to use PHP Type Declarations

PHP has developed into a more strictly typed language in recent years. Type Declarations help with that and are a fairly new addition to PHP,

Iteration

If you have come to JavaScript from a background in Java or C, then you will like the variation on the for loop. It is

Context Object Manipulation

One of the key concepts of JavaScript is the keyword this, which signifies the JavaScript context object. If you write an inner function, you can access

Polymorphic Functions

It is possible to define multiple functions with the same name in JavaScript, and the last one of those that you define will be the