Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help for sql trigger statement 1

Status
Not open for further replies.

irshad2k

Programmer
Oct 4, 2013
3
AE
hi every body can some help me to write sql trigger query I have to tables
table_1 with the columns of id, field1, fieldtext1
and
table_2 with the columns of id, fieldtext2, fieldtext3
i made a query
*********************************************************************************
/****** Object: Trigger [dbo].[trTable2_Change] Script Date: 04/10/2013 15:58:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER trigger [dbo].[trTable2_Change] ON [dbo].[Table_2] AFTER INSERT, UPDATE

AS

UPDATE Table_1
SET
Field1 = I.fieldtext2



FROM Table_1 INNER JOIN Inserted I ON Table_1.ID = I.ID
*********************************************************************************
this is changing a fieldtext2 when i update the field1 but i want other fields as well to be updated like fieldtext3 and fieldtext4
so kindly help me for this
thanks
 
homework?

====================================
The reasonable man adapts himself to the world. The unreasonable one persists in trying to adapt the world to himself. Therefore all progress depends on the unreasonable man. - George Bernard Shaw


 
Do you mean this?

Code:
UPDATE Table_1 
SET    Field1 = I.fieldtext2[!],
       Field2 = I.fieldtextX[/!]
FROM   Table_1 
       INNER JOIN Inserted I 
         ON Table_1.ID = I.ID

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top