問題描述
我想將文件中的數(shù)據(jù)插入到這個(gè)模型的表 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 的子對象.原始數(shù)據(jù)如下所示:
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
結(jié)果應(yīng)該是:
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
我認(rèn)為前進(jìn)的方向是使用 OUTPUT 但我不知道如何在這種相當(dāng)復(fù)雜的情況下使用它(我知道如何進(jìn)行批量插入等)
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.)
期待任何反饋.謝謝.
最好的祝福,
基督徒
推薦答案
我目前正在使用循環(huán)來實(shí)現(xiàn)這一點(diǎn),這是一種解決方案,但速度很慢.真的沒有基于集合的方法嗎?謝謝!
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!
基督徒
這篇關(guān)于將數(shù)據(jù)插入多個(gè)表 - 可能使用 OUTPUT - sql server 2005的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!