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

  • 相关阅读:
    UVALive
    BZOJ2120:数颜色(数状数组套主席树)(带修改的莫对)
    BZOJ-3439:Kpm的MC密码(Trie+DFS序+主席树)
    51nod1674:区间的价值2(分治,利用&和|的收敛性)
    [CQOI2009]DANCE跳舞
    [HNOI2006]超级英雄
    Luogu1613 跑路
    [HZOI 2016]公路修建
    [NOI2014]魔法森林
    [HAOI2006] 旅行
  • 原文地址:https://www.cnblogs.com/meroselove/p/2141682.html
Copyright © 2011-2022 走看看