Using SELECT INTO and INSERT to insert SQL rows
Part one of a four-part series of blogs

There are various ways to insert data into new or existing tables in T-SQL - this blog gives examples of each.

  1. Inserting Data into Tables using SQL (this blog)
  2. Inserting Single Records into a Table
  3. Inserting Multiple Rows of Data into a Table
  4. SELECT INTO - Making a New Table from Existing Rows

This blog is part of a full online tutorial in SQL.  Please have a look too at our introductory and advanced SQL training courses for businesses like yours.

Posted by Andy Brown on 12 October 2012

You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Inserting Data into Tables using SQL

A previous blog showed how to create tables using SQL - this one shows how to populate them with data.

When I was first learning SQL, these were some of the commands that I found the hardest to remember.  The problem is that there are 3 ways to do this, and each does a different thing.  The 3 ways are:

Method What it does
INSERT INTO ... VALUES Inserts a single record into a table.
INSERT INTO ... SELECT Adds a set of rows into a table.
SELECT ... INTO Creates a new tables from a set of rows.
The last two methods use similar syntax, and are particularly easy to confuse.

Aficionados (aficionadi?) of Access should note that the above methods correspond to append and make-table queries.

This blog will consider each of the 3 methods shown above in turn!


This blog has 0 threads Add post