Click here to Skip to main content
15,886,065 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have a VIEW that is the bottom layer (detailed data) of a complex process. I would like to add the information to a History Table each time the View is Selected.

Ideally, I would like for it to execute when the VIEW is released or Closed, similar to an OnClose event. I know there are other methods and I have one in place now, which is called from the Client Side, but would prefer to have a Server Side Solution that requires no management whatsoever.

There may already be a built-in Function or Trigger Method to handle this, and if so, I just cannot find it.

Any help or hints would be greatly appreciated!
Posted
Comments
RossMW 20-Oct-14 17:08pm    
Triggers will only operate on a update, insert or delete. As you are referring to a select then a trigger is not really an option. One way round this is to get your complex process to run a stored procedure after the select from view statement that writes to a history table or does the inserting itself.

1 solution

SQL does not provide trigger on select, but since 2008 you can create an audit object to log server/database events like select...
http://blogs.msdn.com/b/sreekarm/archive/2009/01/05/auditing-select-statements-in-sql-server-2008.aspx[^]
However! Remember that the number of reads (select) is a magnitude larger than writes (insert, update, delete) - and that the reason triggers do not support select. So such log you try to create will be huge hundredfold times than the original table and can became a serious space/performance problem. So think of a scale-able design for you log database and log only the really necessary data!!!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900