SQL creation triggers

Source: Internet
Author: User

SQL creation triggers

Create TRIGGER syntax

Create Trigger Triggername on TableName
For Insert |delete|update
As
Begin

End

Come on, look at that. Create an instance of a trigger

CREATE TABLE Ta1
(
Taid int Identity (1001,1) primary key,
Taname varchar is not NULL,
TASL int
)


CREATE TABLE Ta2
(
ta2id int Identity (1001,1) primary key,
Ta2name varchar is not NULL,
Ta2ysh int,
TA2SL int
)


Create Trigger Tru_ta1
On TA1
For update
As
Begin
if exists (select 1 from ta2,inserted where Ta2id=taid and Ta2ysh < TASL)
Rollback
Else
Update TA2 Set TA2SL=TASL
From inserted where Ta2id=taid
End

The above function is an example

The requirement is when I TASL modify the ta1, first of all compare TA1 table TASL is greater than TA2 table Ta2ysh if greater than TA2 table Ta2ysh is not allowed to modify the operation, otherwise modify the TA2 table TA2SL and then modify TA1 in TASL

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.