zoukankan      html  css  js  c++  java
  • 表中数据的批量插入

    --数据的批量插入

     

    if exists(select name from sys.databases where name='DB_Test')

    drop database DB_Test

    go

     

    create database DB_Test

    go

     

    use DB_Test

    go

     

    if exists(select name from sys.objects where name='T_Table1')

    drop table T_Table1

    go

     

    create table T_Table1

    (

        a nvarchar(10),--

        b nvarchar(10),--性别

        c int,--年龄

        constraint PK_T_Table1_a primary key(a)

    )

    go

     

    insert into T_Table1 values('','',20)

    insert into T_Table1 values('','',22)

    insert into T_Table1 values('','',20)

    go

     

    select * from T_Table1

    go

     

    if exists(select name from sys.objects where name='T_Table2')

    drop table T_Table2

    go

     

    create table T_Table2

    (

        d nvarchar(10),

        e nvarchar(10),

        f int,

        constraint PK_T_Table2_d primary key(d)

    )

    go

     

    --批量插入第一种方式:(目标表一定要存在)

    insert into T_Table2(d,e,f) select a,b,c from T_Table1

    go

     

    insert into T_Table2(d,e,f) select a,b,20 from T_Table1

    go

     

    insert into T_Table2(d,e) select a,b from T_Table1

    go

     

    select * from T_Table2

    go

     

    --第二种方式:(目标表不存在)

    if exists(select name from sys.objects where name='T_Table2')

    drop table T_Table2

    go

     

    select a,b,c into T_Table2 from T_Table1

    go

     

    select a,b into T_Table2 from T_Table1

    go

     

    select * from T_Table2

    go

  • 相关阅读:
    一、逻辑架构与存储引擎
    三、动态SQL
    九、装饰者模式
    二、Mapper映射文件
    八、适配器模式
    测试开发系列之Python开发mock接口(二)
    测试开发系列之Python开发mock接口(三)
    html基础
    seleniumWebdriver浏览器驱动信息汇总
    用30行代码开发一个上传、下载文件的接口
  • 原文地址:https://www.cnblogs.com/meroselove/p/2141682.html
Copyright © 2011-2022 走看看