Client
ClientId | Name |
1001 | John Smith |
1002 | Jake Murray |
Account
ClientId | Balance |
1001 | 15.000,00 |
1002 | 17.000,00 |
The goal is to customize an auditing report in a way to create an additional column and to show a specified value from a related table.
Expected scenario:
PRIMARY_KEY as PRIMARY_KEY_DATA, -- for backward compatibility only, don't use this field! DATA_TYPE char(1) NOT NULL DEFAULT 'A', KEY1 nvarchar(500), KEY2 nvarchar(500), KEY3 nvarchar(500), KEY4 nvarchar(500), KEY5 nvarchar(500) )
To illustrate it, when you open the architecture in the text editor, initiate searching by CTRL+F, and type the KEY4 nvarchar(500) value in the search field (1). When the first result appears, add a comma after KEY4 nvarchar(500) and add KEY5 nvarchar(500) in a new line (2):
In the Search dialog, click the Find next button, to navigate to another part when the modification needs to be applied. Repeat the previous step:
|
Quick tip: The change needs to be applied on both places inside the architecture in order to customize it properly |
KEY1 as ''Key 1'', KEY2 as ''Key 2'', KEY3 as ''Key 3'', KEY4 as ''Key 4'', KEY5 as ''Amount'', d.COL_NAME ''Column Name'',
|
Quick tip: The change needs to be applied on both places inside the architecture in order to customize it properly |
In this way, a column for which you want to show values for, will be created in the report, and the column comes up right after the Key 4 column in the report.
|
Quick tip: The Amount is the name of the column we want to show in the report. If you need to show another column, specify its name instead of Amount. |
From the Advanced tab, click the Manage button:
In the Manage architecture window, click the Open button and navigate to the ApexSQL2053_new.audx architecture file, previously modified:
|
Quick tip: Installing the modified architecture overrides the currently installed architecture. |
Click the Create button:
|
Quick tip: It is important not to execute the script for creating triggers, as there are some changes that need to be made in the Script window |
Add KEY5, and (SELECT TOP 1 Balance FROM dbo.Account a WHERE a.ClientId = OLD.ClientId), as shown below:
If UPDATE([Name]) BEGIN INSERT INTO [TriggerExample].dbo.AUDIT_LOG_DATA ( AUDIT_LOG_TRANSACTION_ID, PRIMARY_KEY_DATA, KEY5, COL_NAME, OLD_VALUE_LONG, NEW_VALUE_LONG, DATA_TYPE , KEY1 ) SELECT @AUDIT_LOG_TRANSACTION_ID, convert(nvarchar(1500), IsNull('[ClientId]='+CONVERT(nvarchar(4000), IsNull(OLD.[ClientId], NEW.[ClientId]), 0), '[ClientId] Is Null')), (SELECT TOP 1 Balance FROM dbo.Account a WHERE a.ClientId = OLD.ClientId), 'Name', CONVERT(nvarchar(4000), OLD.[Name], 0), CONVERT(nvarchar(4000), NEW.[Name], 0), 'A' , IsNULL( CONVERT(nvarchar(500), CONVERT(nvarchar(4000), OLD.[ClientId], 0)), CONVERT(nvarchar(500), CONVERT(nvarchar(4000), NEW.[ClientId], 0)))
After making changes, click the Execute button:
From the ApexSQL Trigger Home tab, click the Standard report button:
The old and the new values appear, but also, a column Amount we specified in the architecture:
|
Quick tip: The specified steps represent modification that affects only the UPDATE statement for the specified column. To apply the same for other operation (INSERT or DELETE), a corresponding changes must be applied in both, the architecture and the triggers creation script. |
© ALL RIGHTS RESERVED. Terms of Use Privacy Cookie Preference Center