I have two tables where I have to add a lot of rows sometimes. Last case was 800000 rows into table1, and 3 times more into table 2.
I use following stored procedure to insert rows, because I don't see way to use bulk copy, considering tables have auto id fields and have a foreign key relation.
CREATE PROCEDURE dbo.AddOrderBookEntry
@Moment datetime,
@LocalTime datetime,
@BB decimal(18,4),
@BO decimal(18,4),
@QBB float,
@QBO float,
@SumTr float = NULL,
@QSumTr float = NULL,
@IV float = NULL,
@InstrumentId bigint,
@AverageValues Averages READONLY
AS
BEGIN
INSERT INTO dbo.OrderBook
VALUES (@Moment,@LocalTime,@BB,@BO,@QBB,@QBO,@SumTr,@QSumTr,@IV,@InstrumentId)
DECLARE @OBID bigint
SELECT @OBID = SCOPE_IDENTITY()
INSERT INTO dbo.OrderbookAverages
select N, BN, [ON], @OBID from @AverageValues
END
GO
It works, but what bothers me is speed. According to my measures, it takes app 1.75 milliseconds for a record to be added. I am measuring speed from .net application that writes data into db. This application is on the same computer as SQL Server.
So question is - is this speed okeyish for the approach I use? Or it can be improved?