A little hard to explain in SQL terms because I am using an in-house technology but Let’s say I have an array of a structs (similar to structs we have in C#, C++, etc) and I want to insert its values in a table.
So one way is a psedu-code that iterates through the array, read the fields of the structs and inserts them into the table like this:
for int i =1 to array.Lenght
{
insert into MyTable values
{
MyTable.Field1 = array[i].Field1;
//etc ...
}
}
but this is bad, because of performnce. If array has ten elements we are calling insert method ten times.
There should be a brillinat way of doing this with just one insert, somehow using JOINS on table and just call insert one time, But I can’t imagine how to do that…
Any thoughts on this are welcome.
Thanks.
This makes sure the query is executed once. This is just an idea, avoiding multiple call insert
Script looks like