将数据插入多个表 - 可能使用 OUTPUT - sql server 2005 [英] insert data into several tables - possibly using OUTPUT - sql server 2005

查看:47
本文介绍了将数据插入多个表 - 可能使用 OUTPUT - sql server 2005的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将文件中的数据插入到这个模型的表 Division 中,这是非常简化的:

I would like to insert data from a file into the table Division of this model which is very much simplified:

create table Statements (
        Id INT IDENTITY NOT NULL
       primary key (Id)
    )

create table Item (
        StatementFk INT not null,
       ItemNameFk INT not null,
       primary key (StatementFk)
    )

create table ItemNames (
        Id INT not null,
       Name NVARCHAR(255) null unique,
       primary key (Id)
    )

create table Division (
        ItemFk INT not null,
       primary key (ItemFk)
    )

alter table Item 
        add constraint FKBCDC2F95A77158D3 
        foreign key (StatementFk) 
        references Statements

    alter table Item 
        add constraint FKBCDC2F957105B2A7 
        foreign key (ItemNameFk) 
        references ItemNames

alter table TaxonomyDivision 
        add constraint FKCFB817265F647111 
        foreign key (ItemFk) 
        references Item

这里 Division 是 Item 的子对象,Item 是 Statements 的子对象.原始数据如下所示:

Here Division is a child object of Item and Item is a child object of Statements. The original data looks like this:

Division1
Division2
Division1
Division3

结果应该是:

ItemNames
1, Division1
2, Division2
3, Division3

Statements
1
2
3
4

Item
1,1
2,2
3,1
4,3

Division
1
2
3
4

我认为前进的方向是使用 OUTPUT 但我不知道如何在这种相当复杂的情况下使用它(我知道如何进行批量插入等)

I think the way forward is to use OUTPUT but I don’t know how to use it in this fairly complicated case (I know how to do a bulk insert etc.)

期待任何反馈.谢谢.

最好的祝福,

基督徒

推荐答案

我目前正在使用循环来实现这一点,这是一种解决方案,但速度很慢.真的没有基于集合的方法吗?谢谢!

I am currently using loops to achieve this which is kind of a solution but very slow. Is there really no set based approach? Thanks!

基督徒

这篇关于将数据插入多个表 - 可能使用 OUTPUT - sql server 2005的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆