1. w3schools.com
    THE WORLD'S LARGEST WEB DEVELOPER SITE

    SQL Tutorial

    SQL HOMESQL IntroSQL SyntaxSQL SelectSQL Select DistinctSQL WhereSQL And, Or, NotSQL Order BySQL Insert IntoSQL Null ValuesSQL UpdateSQL DeleteSQL Select TopSQL Min and MaxSQL Count, Avg, SumSQL LikeSQL WildcardsSQL InSQL BetweenSQL AliasesSQL JoinsSQL Inner JoinSQL Left JoinSQL Right JoinSQL Full JoinSQL Self JoinSQL UnionSQL Group BySQL HavingSQL ExistsSQL Any, AllSQL Select IntoSQL Insert Into SelectSQL CaseSQL Null FunctionsSQL Stored ProceduresSQL Comments

    SQL Database

    SQL Create DBSQL Drop DBSQL Backup DBSQL Create TableSQL Drop TableSQL Alter TableSQL ConstraintsSQL Not NullSQL UniqueSQL Primary KeySQL Foreign KeySQL CheckSQL DefaultSQL IndexSQL Auto IncrementSQL DatesSQL ViewsSQL InjectionSQL Hosting

    SQL References

    SQL KeywordsMySQL FunctionsSQL Server FunctionsMS Access FunctionsSQL OperatorsSQL Data TypesSQL Quick Ref

    SQL Examples

    SQL ExamplesSQL QuizSQL ExercisesSQL Certificate

    SQL SELECT INTO Statement


    The SQL SELECT INTO Statement

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

    SELECT INTO Syntax

    Copy all columns into a new table:

    SELECT *
    INTO newtable [IN externaldb]
    FROM oldtable
    WHERE condition;

    Copy only some columns into a new table:

    SELECT column1, column2, column3, ...
    INTO newtable [IN externaldb]
    FROM oldtable
    WHERE condition;

    The new table will be created with the column-names and types as defined in the old table.You can create new column names using the AS clause.


    SQL SELECT INTO Examples

    The following SQL statement creates a backup copy of Customers:

    SELECT * INTO CustomersBackup2017
    FROM Customers;

    The following SQL statement uses the IN clause to copy the table into a new table in another database:

    SELECT *INTO CustomersBackup2017 IN 'Backup.mdb'
    FROM Customers;

    The following SQL statement copies only a few columns into a new table:

    SELECT CustomerName, ContactName INTO CustomersBackup2017
    FROM Customers;

    The following SQL statement copies only the German customers into a new table:

    SELECT *INTO CustomersGermany
    FROM Customers
    WHERE Country = 'Germany';

    The following SQL statement copies data from more than one table into a new table:

    SELECT Customers.CustomerName, Orders.OrderID
    INTO CustomersOrderBackup2017
    FROM Customers
    LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID;

    Tip: SELECT INTO can also be used to create a new, empty table using the schema of another. Just add a WHERE clause that causes the query to return no data:

    SELECT * INTO newtable
    FROM oldtable
    WHERE 1 = 0;

        1. http://www.mh8dociw.tw | http://m.mh8dociw.tw | http://wap.mh8dociw.tw | http://3g.mh8dociw.tw | http://4g.mh8dociw.tw | http://5g.mh8dociw.tw | http://mobile.mh8dociw.tw | http://vip.mh8dociw.tw | http://ios.mh8dociw.tw | http://anzhuo.mh8dociw.tw | http://1.mh8dociw.tw | http://de.mh8dociw.tw | http://0b.mh8dociw.tw | http://6d7a.mh8dociw.tw | http://b9.mh8dociw.tw | http://221.mh8dociw.tw | 小受被整个宿舍的人qj