Foreign keys are normally straight forwards to use, but there are some very subtle differences between how these work in SQL Server as compared to Access.
When you have a sequence of operations, that needs to produce different result sets for different users, but is too complex to complete in a single or set of layered queries, you need to create a physical table of results.
This is very difficult in Access without giving each user a copy of their own font-end application, or naming the result tables to reflect a users name (and suffering from bloating or fragmentation).
In SQL Server this is very easy, and it is also very easy to link Office applications like Excel or Access to these result sets.
The following example shows how to create a stored procedure in Northwind, which returns a temporary result set. This can be used by any number of users at the same time.
To link to this from Access we create a pass-through query.
This is an excellent solution, as long as you do not need to get at the results using other Access queries. For example trying the following after running the stored procedure will not work.
As an alternative to the above, where you need to persist results over a period of time, possibly whilst a series of stored procedures are executed, and other activities undertaken, you can consider creating a physical table, and adding a UserName field to the table.
Then you will also need a view which filters the data for the specific user.
Our stored procedure must now empty the data for the user and re-populate the data.
The data set now includes the user’s name.
This method offers a great deal of flexibility, as we can now link to the view if required and update data in the view; maybe the temporary data was a result of a user selecting records for further processing.
You can also use this technique when you have legacy or other processes which you need to keep in Access (because of complexity to re-write), but require temporary data. In this case we can link Access to the view, and use Access queries to pump data into the view.
Or you may have a complex sequence of operations which finishes by opening an Excel spreadsheet linked to the view.
The use of the above methods means that may activities which are very difficult to create in Access become far simpler when we have the data in SQL Server.
by Andrew Couch Office Access MVP, Director ASC Associates
andy@ascassociates.biz