C# SQL insert command

后端 未结 5 1787
小蘑菇
小蘑菇 2020-12-01 13:35

Can anyone tell me the following 2 ways of inserting record creates better performance?

Case 1

SqlCommand cmd = new SqlCommand();

f         


        
5条回答
  •  佛祖请我去吃肉
    2020-12-01 14:14

    I don't think the second one will work.

    There is however a syntax in SQL Server 2008 for inserting multiple rows in a single INSERT statement and I think that will be faster than both the options you proposed:

    INSERT INTO test (id, name)
    VALUES
    ('1', 'foo'),
    ('2', 'bar'),
    ('3', 'baz')
     -- etc...
    

    However if you really want high performance, consider using the SqlBulkCopy class.

提交回复
热议问题