select into 與 insert into select


1.select into

  select into 語句把一個表中的數據插入到另一個表中。

  不需要創建臨時表,在運行過程中自動創建。

  基本語法:

    select * into #table_Name from tableName 

     #table_Name 臨時表名;tableName數據源表名

 

2.insert into select

  同樣是把一個表中的數據插入到另一個表中。

  需要創建臨時表,設置字段與數據類型。

  基本語法:

    create table #table_Name (

        column1  int,

        column2  nvarchar(50),

        .......    

      );

    insert into #table_Name (column1,column2,columnn) select value1,value2,valuen from  tableName

    或:insert into #table_Name select  *  from tableName

    #table_Name 臨時表名;tableName數據源表名

    創建臨時表字段的順序要和查詢 tableName 表的字段順序一樣


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM