sql server - How to implement trigger after insertion? -
i have column named htmlcontent
stores html content
in table eemaildata
, column named eemaildataid
unique id
of table or can primary key of table.
now want want create trigger
primary key table , insert eemaildataid
in column htmlcontent
on specific location.
i think take place substring
function. can suggest me other solution?
for need add id
where want replace primary key value
eg: <a href="localhost:19763/bitbucket/guest/... ?guestinvitefwd=uaraiad
and use following trigger
create trigger eemaildata_trigg on eemaildata after insert if exists (select top(1)* eemaildata p join inserted on p.eemaildataid = i.eemaildataid ) begin declare @html varchar(max),@id int select @html=htmlcontent ,@id=eemaildata eemaildata eemaildataid =(select top(1) eemaildataid inserted) update eemaildata set htmlcontent=replace(@html,'uaraiad',@id) eemaildataid=@id end
now after trigger uaraiad
replaced eemaildataid
also can achieve without trigger. following after insert.
declare @html varchar(max),@id int --insert statements set @id=scope_identity() select @html=htmlcontent ,@id=eemaildata eemaildata eemaildataid =@id update eemaildata set htmlcontent=replace(@html,'uaraiad',@id) eemaildataid=@id
Comments
Post a Comment