zoukankan      html  css  js  c++  java
  • 在存储过程中使用表变量实现批量导入

    create table test
    (
        name nvarchar(10) not null,
        sex bit not null,
        age int not null
    )  
    --创建一个自定义类型,他是一个表
    create type Ty_PublicTableType as table (
        name nvarchar(10) not null,
        sex bit not null,
        age int not null
    )
    go
    --创建一个批量导入的存储过程,把刚刚的自定义表类型作为参数
    create proc insert_table
    (
        @table Ty_PublicTableType readonly
    )
    as
    begin
        --整个表插入另一个表
        insert into test select * from @table;
    end
    go
    
    --创建一个表变量,类型依然是刚刚的自定义表类型,不然和存储过程参数类型不匹配
    declare @data_table Ty_PublicTableType
    --为表变量插入数据
    insert into @data_table values ('路人甲',1,11),('友人A',1,17)
    --调用存储过程,把表变量作为参数传入
    exec insert_table @data_table;

    如果要在C#程序中使用,那就是正常调用存储过程的方式,然后参数给datatable类型的数据,但要注意列要匹配

  • 相关阅读:
    宿主机无法访问CentOS7上Jenkins服务的解决办法
    415. Add Strings
    367. Valid Perfect Square
    326. Power of Three
    258. Add Digits
    231. Power of Two
    204. Count Primes
    202. Happy Number
    172. Factorial Trailing Zeroes
    171. Excel Sheet Column Number
  • 原文地址:https://www.cnblogs.com/nicopoiduang/p/11082938.html
Copyright © 2011-2022 走看看