• Home
  • SQL SELECT INTO Statement

    In SQL Server, the SELECT INTO statement is primarily used to create a new table and insert data into it from an existing table or result set. Here's the correct syntax for the SELECT INTO statement in SQL Server:


    sql
    SELECT column1, column2, ...
    INTO new_table
    FROM source_table
    WHERE condition;

    - `column1, column2, ...`: The specific columns you want to select from the source table or query result.
    - `new_table`: The name of the new table that will be created.
    - `source_table`: The table or tables from which you want to select data.
    - `condition`: An optional condition that filters the rows selected from the source table(s).


    Here's an example to illustrate how to use the SELECT INTO statement in SQL Server:

    sql
    SELECT customer_id, customer_name, email
    INTO new_customers
    FROM customers
    WHERE country = 'USA';

    In this example, the SELECT INTO statement creates a new table called `new_customers` and inserts data into it from the `customers` table. Only the `customer_id`, `customer_name`, and `email` columns are selected from the `customers` table, and the rows are filtered based on the condition `country = 'USA'`. The new table `new_customers` will have the same column names and data types as the selected columns from the source table.


    Please note that the SELECT INTO statement in SQL Server is used specifically for creating a new table based on the selected data. It differs from the INSERT INTO statement, which inserts data into an existing table.


    About the Author



    Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

    We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





     PreviousNext