开发者

Many Small SQL calls or Few Large SQL calls?

I have an application that stores approximately 24 fields of data about a machine. Am I better off having one large SQL statement that inserts all of this information, or should I use many small statement开发者_StackOverflows as the date is entered?

An example: CPU/Memory/HDD is one group, another would be client contact/phone/address. Am I better off getting all information and then creating the information in the table or should I enter the first group as the data is entered, then enter the second group, etc?

The fields will all be present on the same page, and views have been created for each group.


If everything is on one page (you have all data available at one) do one INSERT, otherwise you will be doing an INSERT and then a few UPDATEs, which is always slower (because you are doing a few operation instead of one) and more complex for you to write. In your case the speed difference will be insignificant.


You are better off doing a single INSERT for all fields.


For inserts and updates, you'll probably be better with large inserts, rather than a small insert followed by multiple updates.

Where large queries are sometimes less efficient than small ones is when doing large, complex joins or sub-selects. And then, you really need to test both forms to see which is more efficient.

You may also find that smaller queries are better even for inserts and updates in rare cases where you have a lot of locking/contention going on, or complex foreign key relationships or other constraints.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜