I'm using DataAdapter
Batch to insert to many to many table
the batch size = 1000
i have 3 tables
- SCHOOL (ID, Name)
- STUDENT (ID,Name)
- SCHOOL_STUDENT (SCHOOL_ID, STUDENT_ID)
I'm trying to insert around 700K rows to the table SCHOOL_STUDENT but it's very slow i'm passing the school name and the student name to the stored procedure
(
@schoolName varchar(100),
@studentName varchar(50)
)
AS
BEGIN transaction
declare @scoolId int,@studentId int
set @scoolId = (select ID from SCHOOL where [SCHOOL_NAME] = @schoolName)
set @studentId = (select ID from STUDENT where STUDENT_NAME = @studentName)
INSERT INTO [dbo].SCHOOL_STUDENT
(SCHOOL_ID,STUDENT_ID)
VALUES
(@scoolId,@studentId)
commit transaction
but this takes around 1 hour to run.
How can i speed this,
as i don't know the school_Id
neither the student_Id
in advance, then i have to always select them inside the stored procedure. (is there a better way)
the flow of the application is first inserting all students, then insert all schools then link them in the table school_student.