August 25, 2011 at 11:27 am
Hi Everyone,
I want to create an auditing table.
Below is my table structure..
create table maintable
(
id int,
memberid int,
customerid int
)
and below is my auditing table..
create table Audittable
(
HistoryId int identity(1,1),
id int,
memberid int,
customerid int
)
Now I want that if anyone update maintable(any column) then I want the old row from the main table into Audittable.
Please guide me How can I achieve it.
August 25, 2011 at 11:46 am
Can I create trigger on Table ?? I mean logic that check that any update statement occur on the table or not and if occur then insert old rows from the table to mailtable.
August 25, 2011 at 1:32 pm
krishusavalia (8/25/2011)
Can I create trigger on Table ?? I mean logic that check that any update statement occur on the table or not and if occur then insert old rows from the table to mailtable.
Yes this very possible and pretty easy. Take a look at the MSDN article about triggers. Try to work through this and then post back when you run into some problems. I will be happy to help you work this.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
August 25, 2011 at 1:35 pm
In fact, there is a thread from today about this very topic. Take a look at Craig's post here. He gives a great pseudocode skeleton. Read the rest of the thread, give it a try and let us know if you run into any problems.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
August 25, 2011 at 2:35 pm
I solve it by my self through reading some articles.
Thanks
August 25, 2011 at 2:39 pm
You're welcome. Glad you were able to solve it. It is customary around here to post your solution (at least something close as it is not always possible to post your entire solution) so that others searching for the same issue can learn from your example and solution. If you can find some time that would be fantastic.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply