sql server - How can I increase the speed of many insert statements? -
i have .net project receiving data, processing it, , writing sqlserver database. let's have following code.
private sub insertrecord(val1 integer, val2 integer, byref dbconnection data.sqlclient.sqlconnection) dim cmd sqlcommand = nothing if dbconnection.state = connectionstate.open dim strsql string = "insert mytable(value1, value2) values(@value1, @value2)" cmd = new sqlcommand(strsql, dbconnection) cmd.parameters.addwithvalue("@value1", val1) cmd.parameters.addwithvalue("@value2", val2) dim returnval = cmd.executenonquery() if not returnval 'do other stuff end if cmd.dispose() end if end sub
sometimes need insert records - 500 per second. is, can handle around 200 inserts per second. there way combine multiple commands processed @ once? need know results of each insert statement.
you need sql server bulk insert made available through sqlbulkcopy
class. use 1 transaction rows. blindingly fast.
indexing plays this, many other things. not enough information here comment specifically.
Comments
Post a Comment