Okay so I have a table ERD designed like so... for regular bulk inserts
(source: iforce.co.nz)
And a tab delimited \t
text file with information about each customer (consists of about 100,000+ records).
# columnA columnB columnC
data_pointA data_pointB data_pointC
And a stored procedure that currently does its intended job fine.
CREATE PROCEDURE import_customer_from_txt_para @filelocation varchar(100)
AS BEGIN
TRUNCATE TABLE dbo.[customer_stg]
DECLARE @sql nvarchar(4000) = '
BULK INSERT customer_stg
FROM ''' + @filelocation + '''
WITH
(
FIRSTROW=14,
FIELDTERMINATOR=''\t'',
ROWTERMINATOR=''\n''
)';
print @sql;
exec(@sql);
END
But my question is about the relationship between customer_table
and customer_stg
is it possible to include a customer_id within the customer_stg
bulk insert? with something like so? ( I'm not sure how to apply the foreign key parameter @customer_sk
to the bulk insert ).
CREATE PROCEDURE import_customer_from_txt_para @filelocation varchar(100), @customer_sk int
AS BEGIN
TRUNCATE TABLE dbo.[customer_stg]
DECLARE @sql nvarchar(4000) = '
BULK INSERT customer_stg
FROM ''' + @filelocation + '''
WITH
(
FIRSTROW=14,
FIELDTERMINATOR=''\t'',
ROWTERMINATOR=''\n''
)';
print @sql;
exec(@sql);
END
Preferably after each bulk-insert I'd wish to be able to relate the data between the two tables.
(source: iforce.co.nz)