• 在存储过程中使用表变量实现批量导入


    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类型的数据,但要注意列要匹配

  • 相关阅读:
    优化总结文章链接
    帧同步、状态同步
    ecs
    AStarPathFinding
    unity 热更方案对比
    C#数据类型
    JavaScript基础
    CSS中margin和padding的区别
    css选择器
    hadoop中使用shell判断HDFS文件是否存在
  • 原文地址:https://www.cnblogs.com/nicopoiduang/p/11082938.html
Copyright © 2020-2023  润新知