0
我有一个客户表,其中包含客户的详细信息。以下是字段使用外键将BULK INSERT插入表
CustId (PrimaryKey), Name, Date of Birth
我有另一个表,资产信息。以下字段有 -
AssetId (PrimaryKey), AssetValue, CustId (Foreign Key Reference)
我的CSV文件是这样
Name, Date of Birth, AssetValue
,我必须把它插入到两个表。我分割了CSV文件,一个带有出生日期的名称,另一个带有AssetValue。
这里是我做过什么 -
/*Creation of Table*/
CREATE TABLE Customer
(
custid int identity(1,1) not null,
name nvarchar(50) not null,
dateofbirth datetime not null,
primary key (custid)
)
CREATE TABLE Asset
(
AssetId int identity(1,1) not null,
AssetDollars money not null,
primary key (AssetId),
CustId int foreign key references Customer(custid)
)
对于批量插入我所做的就是这一点。我使用两个字段名称和出生日期为客户创建了一个视图,然后插入记录。
这里是我做过什么 -
CREATE view vw_bulk_insert_customer
AS
SELECT name, dateofbirth FROM customer
BULK INSERT vw_bulk_insert_customer
FROM 'C:\Customer.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
这工作完全正常。
现在,我该如何使用CustId将它插入Asset表中(因为它在CSV文件中不可用)。
我不允许更改CSV文件。我可以分割CSV文件,这是允许的。
我不知道该怎么做......任何想法?