How to get all the values from the deleted row into a column in sql server 2008 -


tbl_employee

id  name        source 1   sanders     outsource 

tbl_audit

name    columnnames columnvalues 

on delete of employee tbl_employee, trying insert info tbl_audit.

i hard coding values tblname , columnnames, cannot figure out how values deleted row columnvalues column (comma delimited).

any guidance appreciated.

example: employee 1 deleted

create trigger trigger_delete on tbl_employee delete  insert tbl_audit  (tblname, columnnames, columnvalues)  values   (  'tbl_employee',  'id, name, source',  select stuff(select ',' + tbl_employee.id, tbl_employee.name, tbl_employee.source deleted tbl_employee.id in(select deleted.id deleted))   )    tbl_employee.id in(select deleted.id deleted) 

you can use sys.columns system view fetch columns of database table on sql server

select name sys.columns object_id = object_id('tblname') 

my solution changed data (updated or deleted) once used custom history tables logging in sql server. perhaps can check well. requires 1 history table targeted source table logging.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -