SQL Server triggers cascade inserts, CASCADE updates for tables

Source: Internet
Author: User

First, two tables were created, Test1 and test2, with the expectation that the relevant records of Test2 could be changed at the same time when the test1 was changed. Assume that Test1 is the same as the table structure of Test2, as shown in the following table

Name Age

The trigger implements a cascade insert:

Create trigger Test3on test1after Insertasinsert into test2 select Name,age from inserted
Triggers implement cascading updates:
Create Trigger Test4on test1after updateas beginupdate test2 Set age = A.age from test2,inserted as a where a.name = Test2 . nameend
Perform:
INSERT into test1 values (' Merle ', ' 99 ');
Output:
SELECT * from Test1, "Merle 99" select * from Test2; "Merle 99"

SQL Server triggers cascade inserts, CASCADE updates for tables

Related Article

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.