When an SQL trigger modifies the F1 field in the test table, it also modifies the F2 field according to the condition.

Source: Internet
Author: User
Code
-- When the F1 field in the test table is modified, the F2 field is also modified according to the condition.
Alter   Trigger   [ DBO ] . [ Updatetest1 ]   On   [ DBO ] . [ Test ]  
For   Insert , Update , Delete  
As
Begin

If Update(F1)
 Declare
 @ FID Int,
 @ F1 Int 

Set   @ FID = ( Select FID From Inserted) -- Obtain the ID of the modified row
Set   @ F1 = ( Select F1 From Inserted) -- Get modified content

Begin
If ( Select F1 From Inserted) >   0
Begin
Update Test Set F2 =   ' 5 '   Where FID =   @ FID
End
If ( Select F1 From Inserted) <=   0
Begin
Update Test Set F2 =   ' 6 '   Where FID =   @ FID
End
End
End

An example of triggering an SQL statement by modifying a field

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.