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 表的字段顺序一样

posted @ 2019-09-09 15:34  刺激  阅读(8031)  评论(0编辑  收藏  举报