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

  • 相关阅读:
    常用的Dos命令
    关于CSS3
    数据渲染
    jQuery中的AJAX
    AJAX
    面向对象3
    克隆对象、对象继承
    面向对象2
    面向对象1
    面向对象
  • 原文地址:https://www.cnblogs.com/meroselove/p/2141682.html
Copyright © 2011-2022 走看看