SELECT INTO copies data from one table into a new table.
SELECT INTO creates a new table located in the default filegroup.
Copy products that cost more than $75 to a new LuxeProduct table.
SELECT *
INTO LuxeProduct
FROM Product
WHERE UnitPrice > 75
Next, run this query:
SELECT * FROM LuxeProduct
| Id | ProductName | SupplierId | UnitPrice | Package | IsDiscontinued |
|---|---|---|---|---|---|
| 9 | Mishi Kobe Niku | 4 | 97.00 | 18 - 500 g pkgs. | 1 |
| 20 | Sir Rodney's Marmalade | 8 | 81.00 | 30 gift boxes | 0 |
| 29 | Thüringer Rostbratwurst | 12 | 123.79 | 50 bags x 30 sausgs. | 1 |
| 38 | Côte de Blaye | 18 | 263.50 | 12 - 75 cl bottles | 0 |
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 by the query.
| SUPPLIER |
|---|
| Id |
| CompanyName |
| ContactName |
| City |
| Country |
| Phone |
| Fax |
SELECT Id, CompanyName, ContactName,
City, Phone
INTO SupplierUSA
FROM Supplier
WHERE Country = 'USA'
These are the new SupplierUSA rows.
| Id | CompanyName | ContactName | City | Phone |
|---|---|---|---|---|
| 2 | New Orleans Cajun Delights | Shelley Burke | New Orleans | (100) 555-4822 |
| 3 | Grandma Kelly's Homestead | Regina Murphy | Ann Arbor | (313) 555-3349 |
| 16 | Bigfoot Breweries | Cheryl Saylor | Bend | (100) 555-4822 |
| 19 | New England Seafood Cannery | Robb Merchant | Boston | (617) 555-3267 |