Professional SQL Editor For A Fraction Of The Price

Inserting data into a table

Adding rows of data to a database table is accomplished by inserting data into the table.

Basic SQL Insert Syntax

A very basic query will insert a row of data into a database table as long as the value count matches the column count existing in the table. Values must also be provided in matching order to the data types accepted in the table.

insert into table_name
values (value_one, value_two, value_three, ...)
SQL Insert Syntax Specifying Columns

Data can be inserted into specific columns in specific orders using a more complex insert query. The column order must first be presented and then the values must match the desired order. Columns can be omitted if the table allows for null values.

insert into table_name (column_one, column_two, column_three, ...)
values (value_one, value_two, value_three, ...)
Demo Table

Here is a very simple database table which holds information about people. The table is called Person. The table has only four rows and four columns to keep things simple in the examples.

first_name last_name city state
Nic Raboy Merced California
Jane Doe Newark New York
John Lee Las Vegas Nevada
Maria Campos Modesto California
Example SQL Queries

The following SQL statement will insert a complete row of data into the Person table.

insert into Person
values ('Victor', 'Lara', 'Avenal', 'California')

The following SQL statement will insert a row of data into the Person table. However, the column order is specified and since we don't know the last_name it is omitted from the insert. Columns can only be omitted if the table allows for null values.

insert into Person (city, state, first_name)
values ('Valparaiso', 'Indiana', 'Francisco')

After executing the previous examples, the database table now has two new rows of data and looks like as follows:

first_name last_name city state
Nic Raboy Merced California
Jane Doe Newark New York
John Lee Las Vegas Nevada
Maria Campos Modesto California
Victor Lara Avenal California
Francisco Valparaiso Indiana