Oracle cascading deletion trigger and oracle trigger

Source: Internet
Author: User

Oracle cascading deletion trigger and oracle trigger

Create table student (-- CREATE a STUDENT TABLE
Id number (10) primary key, -- PRIMARY KEY ID
SNAME VARCHAR2 (20 ),
CLASSNAME VARCHAR2 (20) -- class ID

);

Insert into student values (1, 'Tom ', 1 );
Insert into student values (2, 'jack', 1 );
Insert into student values (3, 'bay ', 2 );
Insert into student values (4, 'john', 3 );

Create table classtab (-- CREATE a class TABLE
Classid number (2) primary key, -- class ID
CNAME VARCHAR2 (20)
);

Insert into classtab values (1, '3g ');
Insert into classtab values (2, 'svse ');
Insert into classtab values (3, 'gis ');
Insert into classtab values (4, 'em ');

-- When a trigger is created to delete a class, all student information of the class is also deleted.
CREATE OR REPLACE TRIGGER MYTRIGGER
AFTER DELETE
ON CLASSTAB
FOR EACH ROW
BEGIN
Delete from student where classname =: old. CLASSID;
END;

Delete from classtab where classid = 2; deleting the third record of the class student table whose CLASSID is 2 in the class table will also be deleted.

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.