- Local time
- Today, 12:21
- Joined
- Feb 19, 2002
- Messages
- 46,888
Clever analogy Minty.
Saved querydefs (even those that reference form variables) are compiled the first time they are executed and the execution plan is saved. Then every time the query runs, that same execution plan is used. When you send queries to the server, whether they originate as querydefs or SQL strings, there is no ability to pre-compile them. The server creates the execution plan on the fly each time. The only way to get around this is to use views. Views are updateable as long as a plain query would be updateable. So make sure you include all the PK's in the selection list because if you are not careful, you can make the view not updateable.
I always used querydefs for all queries unless I actually need to build the SQL String on the fly as I might for a complex search form. So, even though the query is going to be sent to the server where an execution plan will be built on the fly, there is some processing already decided on so Access has to do slightly less work for each execution.
This used to be more problematic in the early days of Access. Using embedded SQL used to cause extreme bloat because Access couldn't clean up after itself without a compact. Access has gotten more efficient in this area and so although there is a very slight time difference, it is no longer imperative to always use querydefs for efficiency. I use querydefs because they are easier to change, plus they are reusable. embedded SQL is what it is and if you have to modify something, you have to modify it in every separate SQL string.
Saved querydefs (even those that reference form variables) are compiled the first time they are executed and the execution plan is saved. Then every time the query runs, that same execution plan is used. When you send queries to the server, whether they originate as querydefs or SQL strings, there is no ability to pre-compile them. The server creates the execution plan on the fly each time. The only way to get around this is to use views. Views are updateable as long as a plain query would be updateable. So make sure you include all the PK's in the selection list because if you are not careful, you can make the view not updateable.
I always used querydefs for all queries unless I actually need to build the SQL String on the fly as I might for a complex search form. So, even though the query is going to be sent to the server where an execution plan will be built on the fly, there is some processing already decided on so Access has to do slightly less work for each execution.
This used to be more problematic in the early days of Access. Using embedded SQL used to cause extreme bloat because Access couldn't clean up after itself without a compact. Access has gotten more efficient in this area and so although there is a very slight time difference, it is no longer imperative to always use querydefs for efficiency. I use querydefs because they are easier to change, plus they are reusable. embedded SQL is what it is and if you have to modify something, you have to modify it in every separate SQL string.