INSERT INTO new SQL table with SELECT INTO



By:

Overview

Since we have already mentioned the SELECT command in this INSERT tutorial, let's see how to use the SELECT command to create a new table and populate with data from an existing table. 

Explanation

In this example we are creating a new table called dbo.CustomerEmailAddress with only the CustomerID and EmailAddress from the dbo.Customer table.  See the code below.

-- 1 - Populate the dbo.CustomerEmailAddress table
SELECT CustomerID, EmailAddress
INTO dbo.CustomerEmailAddress
FROM dbo.Customer;
GO
-- 2 - Verify the data in the dbo.CustomerEmailAddress table
SELECT * 
FROM dbo.CustomerEmailAddress;
GO

Last Update: 9/16/2011






Comments For This Article




Sunday, January 24, 2016 - 4:23:52 PM - Jeremy Kadlec Back To Top (40486)

Joe,

Thank you for the clarification.

Thank you,
Jeremy Kadlec
Community Co-Leader


Friday, January 22, 2016 - 5:09:31 PM - Joe Celko Back To Top (40482)

You might want to mention that this is pure original Sybase dialect. In ANSI/ISO Standard SQ, the SELECT..INTO.. is a called a singleton SELECT and it returns only one row.

 

 



download








get free sql tips
agree to terms


Learn more about SQL Server tools