Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
iganesh2k2
Starting Member
6 Posts |
Posted - 2007-05-31 : 02:55:04
|
| In my application, i have to replace trigger.please find the scenariolet us consider a tableEmployee--------1)EMP_ID2)Column13)Column2...50)Column50Employee table is having 1 million records. i have written update trigger on this table to track any changes in column for all rows by following code in trigger.--This query is to check any changes in COLUMN1SELECT @INSERTED_VAL=I.COLUMN1@DELETED_VAL=D.COLUMN1FROM INSERTED I,DELETED D,EMPLOYEE EWHERE E.EMP_ID=D.EMP_ID AND E.EMP_ID=E.EMP_IDif any changes found, then trigger will insert record to Log table for changes in every column.the structure of LOG table is as follows.LOG---1)Emp_ID2)Updated_User3)Updated_Column4)Before_Value5)After_ValueSuppose if i change 2 columns of 10 Emplyee. then trigger will be fired to insert 20 rows to LOG table.for minimum number of record trigger is working fine.if i change 10,000 records, trigger takes more time (more than 2 hour to insert 20,000). as we know very well, trigger will be fired for each row.so in this case,trigger will be fired for 10,000 times which completely hangs my application. please suggest me the new way to replace this trigger. |
|
|
bpgupta
Yak Posting Veteran
75 Posts |
Posted - 2007-05-31 : 03:12:59
|
| Change you log table structure and add the all the orginal columns + New Values Columns .Now in the trigger use columns_update() funtion to find out which columns updated and update the respective column in Log table.By this way u have avoid the mutiple row for mutiple column updation of single row.you hav refer the columns_update in BOL. |
 |
|
|
iganesh2k2
Starting Member
6 Posts |
Posted - 2007-05-31 : 06:11:58
|
| i could not change the structure. this application was already in production in my client. please tell me the steps clearly. its very urgent. |
 |
|
|
|
|
|