Hi friend,
I have found a solution using After Update Trigger.
Just assume am having a table Employee with the following columns(Eid,Name,Salary)
Eid is primary key.. so It can't be changed.
My trigger will show what are all the columns are updated.
I have used 2 System virtual tables(inserted and deleted).
As I know what are all the columns are existed in my table,to create a trigger for my table, I just use column names directly.
Code:-
Alter trigger Tr_UpdateEmp
On Employee
After Update
As
Begin
declare @Eid int,@name varchar(20),@Salary money,@Eid1 int,@name1 varchar(20),@Salary1 money,@reuslt varchar(20),@reuslt1 varchar(20),@reuslt2 varchar(20)
Set @Eid=0
set @name=''
set @Salary=0
Set @Eid1=0
set @name1=''
set @Salary1=0
set @reuslt=''
set @reuslt1=''
set @reuslt2=''
select @Eid=Eid,@name=name,@Salary=Salary from Inserted
Select @Eid1=Eid,@name1=name,@Salary1=Salary from Deleted
select @reuslt1=case when @name<>@name1 Then 'Name' End
select @reuslt2=case when @Salary<>@Salary1 Then 'Salary' End
IF @reuslt1 <>'' and @reuslt2<>''
Begin
Select Name,Salary from Employee where Eid=@Eid
End
Else IF @reuslt1 ='' and @reuslt2<>''
Begin
Select Salary from Employee where Eid=@Eid
END
Else IF @reuslt1 <>'' and @reuslt2=''
Begin
Select Name from Employee where Eid=@Eid
END
END
--Please keep me in touch.
Aravinth.G
SQL Developer,
Kadamba Technologies Pvt.Ltd,
Chennai
Email:- [Deleted] // Don't mention your mail id here