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

  • 相关阅读:
    实验四实验报告————Android基础开发
    结对编程之四则运算——第二阶段报告
    实验三实验报告
    结对编程之四则运算——第一阶段报告
    第九周作业
    第八周作业
    第七周实验 实验2
    第七周作业
    第五周作业
    20155336 2017-2018 1 《信息安全系统设计基础》2017-9-27课堂实践
  • 原文地址:https://www.cnblogs.com/meroselove/p/2141682.html
Copyright © 2011-2022 走看看