SQL SELECT INTO

SQL SELECT INTO Statement

SELECT INTO copies data from one table into a new table.

SELECT INTO creates a new table located in the default filegroup.

Example

#

Problem: Copy products that cost more than $75 to a new LuxeProduct table.

SELECT * 
  INTO LuxeProduct
  FROM Product
 WHERE UnitPrice > 75

Syntax

SELECT INTO syntax.

SELECT column-names
  INTO new-table-name
  FROM table-name
 WHERE condition 

Note: The new table will have column names as specified in the query.


More Examples

SQL SELECT INTO New Table

SUPPLIER
Id
CompanyName
ContactName
City
Country
Phone
Fax
Problem: Copy all suppliers from the USA over to a new SupplierUSA table.
SELECT * 
  INTO SupplierUSA
  FROM Supplier
 WHERE Country = 'USA'
Result:  4 rows inserted

The records in the newly created SupplierUSA table.

Id CompanyName ContactName City Country Phone Fax
2 New Orleans Cajun Delights Shelley Burke New Orleans USA (100) 555-4822 NULL
3 Grandma Kelly's Homestead Regina Murphy Ann Arbor USA (313) 555-5735 (313) 555-3349
16 Bigfoot Breweries Cheryl Saylor Bend USA (100) 555-4822 NULL
19 New England Seafood Cannery Robb Merchant Boston USA (617) 555-3267 (617) 555-3389

You may also like



Guides