tediousjs / node-mssql

Microsoft SQL Server client for Node.js
https://tediousjs.github.io/node-mssql
MIT License
2.24k stars 471 forks source link

The bulk method creates an additional column when trying to bulk insert into a table with a foreign key #1691

Closed mikinho closed 2 weeks ago

mikinho commented 3 months ago

The bulk method creates an additional column when trying to bulk insert into a table with a foreign key

Expected behaviour:

The insert prepared statement to be the below

insert into [FAKEDB].[dbo].[Blah] ( [RunGUID], [S199], [S198] ) values ( ?, ?, ? )

Actual behaviour:

insert into [FAKEDB].[dbo].[Blah] ( [RunGUID], [RunGUID], [S199], [S198] ) values ( ?, ?, ?, ? )

Configuration:

CREATE TABLE [dbo].[Blah](
    [RunGUID] [uniqueidentifier] NOT NULL,
    [S199] [float] NULL,
    [S198] [float] NULL,
) ON [PRIMARY]

--- With the below FK it breaks, removing it fixes
ALTER TABLE [dbo].[BLAH]  WITH CHECK ADD  CONSTRAINT [FK_Blah_Run] FOREIGN KEY([RunGUID])
REFERENCES [dbo].[Run] ([RunGUID])
GO

ALTER TABLE [dbo].[Blah] CHECK CONSTRAINT [FK_Blah_Run]

Software versions

dhensby commented 3 months ago

Do you have any code to replicate the problem?

mikinho commented 3 months ago

I missed your response, sorry. I'll add code sample.