메뉴 닫기

SQL SELECT INTO Statement

The SQL SELECT INTO syntax

The general syntax is:

  1. SELECT columnnames
  2. INTO newtablename
  3. FROM tablename
  4. WHERE EXISTS
  5. (SELECT columnname
  6. FROM tablename
  7. WHERE condition)

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


 

SQL SELECT INTO Example

Problem: Copy all suppliers from USA to a new SupplierUSA table.

  1. SELECT * INTO SupplierUSA
  2. FROM Supplier
  3. WHERE Country = ‘USA’

Results: 4 rows affected
Here are the records in the newly created table SupplierUSA:

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

댓글 남기기

이메일은 공개되지 않습니다.