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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Triggers... a newbie howto question

Status
Not open for further replies.

nickmollberg

Programmer
Aug 2, 2004
29
US
I need to create a trigger that does the following:
When a user inserts or modifies a record in tableA, if a certain column 'ColStatus' is equal to 'Complete' then I need to change a value in tableB to reflect this.

Can anybody point me to a good syntax example, or a howto for how I should go about this?
 
SQL Books online has some good trigger examples.

Assuming some relationship exists between tableA and tableB this code should get you started.
Code:
Create Trigger trgUpdate on TableA
For Insert, Update
As

Update TableB Set col1 = 'value'
Where Exists
 (Select * From inserted
  Where inserted.relatedcol = tableb.relatedcol
    And inserted.colstatus = 'complete')

If you want to get the best answer for your question read faq183-874 and faq183-3179.
Terry L. Broadbent - DBA
SQL Server Page:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top