Learn more about SQL Server tools

mssqltips logo
 

Tutorials          DBA          Dev          BI          Career          Categories          Webcasts          Whitepapers          Today's Tip          Join

Tutorials      DBA      Dev      BI      Categories      Webcasts

DBA    Dev    BI    Categories

Next Webcast - Simple SQL Server Reporting - Click Here to Register
 

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




More SQL Server Solutions











Post a comment or let the author know this tip helped.

All comments are reviewed, so stay on subject or we may delete your comment. Note: your email address is not published. Required fields are marked with an asterisk (*).

*Name    *Email    Email me updates 


Signup for our newsletter
 I agree by submitting my data to receive communications, account updates and/or special offers about SQL Server from MSSQLTips and/or its Sponsors. I have read the privacy statement and understand I may unsubscribe at any time.



    



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

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

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.

 

 


Learn more about SQL Server tools