Implementing two data insertion problems for tables with primary foreign key relationships through triggers

Source: Internet
Author: User

Table: T_users,t_user_except_work, where the primary key ID in t_users and the foreign key in T_user_except_work are sequence sequence_users. Currval's self-growth sequence.

More generally, insert a piece of data into the T_users table and insert a related data through the trigger at T_user_except_work.

Attention:

The sequence has the following two properties

Currval: Returns the current value of the sequence;

Nextval: Returns the value of the current sequence value increment by one step.

You can use the Currval property only after you have issued at least one nextval.

Note that the delay option is checked.

Create or Replace Trigger Trigger_user_except_work
After insert on T_users
For each row
Declare
--Local variables here
Begin
INSERT INTO T_user_except_work
(Id,except_city,except_position,job_categoryid,except_salaryid,userid)
Values
(Sequence_users. Currval, ', ', ', ', ', sequence_users. Currval);
End Trigger_user_except_work;

T_users table:

T_user_except_work table:

Implementing two data insertion problems for tables with primary foreign key relationships through triggers

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.