October 13, 2010 at 2:11 am
Greetings ,,,
i have read about guid recently and i found that it helps to find the version of a row
now lets say i have a row with columns empID,,EmpName
and a row 1,hatem
if that row is updated then we will have a new version of this row ,,so it will have 2 GUIDs old & New
i want to make a trigger on that table when updated it takes the value of Old and New Guid and insert it in new table called (UpdatedGuidsTable) ,,with columns Old Guid,,New Guid
any suggestion will be highly apperciated
thnx
October 13, 2010 at 5:39 am
you might be mixing information from a different database system...as far as i know, I SQL Server there is not a GUID associated with the old/new rows;
you have the rows available in the INSERTED/DELETED virtual tables in a trigger or as an output clause, and there is some undocumented functions where you can retrieve the partitionID/PageID/RowID for a given row of data, but there is not a GUID;
after the INSERTED row of data is put into the current page of data, saving that information related to the INSERTED/DELETED row identifier would have no value anyway...you cannot go back and select it, as the memory is freed up and available ot hte next process.
Maybe you want to audit the actual data that is changed instead, and keep old vs new values?
Lowell
October 13, 2010 at 6:36 am
thnx SScert. for ur post
yes i want to audit data and keep new / old values
can u suggest me the best practice to do so
thnx
October 13, 2010 at 8:52 am
well everything depends on what you want to do;
there's usually a reason why you want to audit old and new data; typically you create an audit table with nearly the same structure as the table to be audited, and the trigger inserts old and new rows into the audit table.
there are alots of articles and forum posts on the subject, take a look at some of them, and then post what you are really trying to accomplish:
http://www.sqlservercentral.com/search/?q=audit+trigger
Lowell
October 13, 2010 at 10:28 am
Since you're on SQL 2008 (at least you posted on that forum), you might want to investigate "Change Data Capture".
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply