0

I am using an Azure SQL database and I'm wondering if there is a limit on how many records I can insert at once. I have a case where I need to insert 7000+ records.

If there is a limit, anyone know a good way of inserting the records in batches?

foreach (var records in records)
{
    db.Records.Add(record);
}

db.SaveChanges();
tqrecords
  • 542
  • 1
  • 5
  • 20

1 Answers1

1

There is not straight answer on this question. Off course there is a limit on how many record you can insert. This depends on many things like 32/64bit / Memory / DB size / transaction size / add method to ef / number of records in one action / transactions locks on your db in a production situation etc. You can write some test that checks how big the chucks have to be like: fastest-way-of-inserting-in-entity-framework. Or you can use AddRange: Ef bulk insert.

db.AddRange(records);
db.SaveChanges();

You have to decide on if you need to insert the records in one transaction or you can use a number of transaction to keep your table locks smaller.

Community
  • 1
  • 1
Peter
  • 27,590
  • 8
  • 64
  • 84