Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7566081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:19:19+00:00 2026-05-30T14:19:19+00:00

Trigger actually. But how do i make this in mysql-workbench. So that anytime i

  • 0

Trigger actually. But how do i make this in mysql-workbench. So that anytime i have any new records in table1 it creates a new record referencing table1.id to table2.parentid ?

enter image description here

--- [OK] --- This is created
CREATE  TABLE IF NOT EXISTS `test`.`table1` (
  `id` BIGINT(20) NOT NULL AUTO_INCREMENT ,
  `name` VARCHAR(45) NULL ,
  PRIMARY KEY (`id`) )
ENGINE = InnoDB

--- [FAIL] --- #1005 - Can't create table 'test.table2' (errno: 150)
CREATE  TABLE IF NOT EXISTS `test`.`table2` (
  `id` BIGINT(20) NOT NULL AUTO_INCREMENT ,
  `parentid` VARCHAR(45) NULL ,
  `table1_id` BIGINT(20) NOT NULL ,
  PRIMARY KEY (`id`) ,
  INDEX `fk_table2_table1` (`parentid` ASC) ,
  CONSTRAINT `fk_table2_table1`
    FOREIGN KEY (`parentid` )
    REFERENCES `test`.`table1` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB

Follow up:

1) Mysql workbench do not offer that

2) Click the table1 > click the triggers tab bottom > write

-- trigger module initiate
DELIMITER $$
CREATE TRIGGER triggertest1 BEFORE INSERT ON table1
  FOR EACH ROW BEGIN
    INSERT INTO table2 SET parentid = NEW.id; 
  END;
$$
DELIMITER ; --- return to normal
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T14:19:20+00:00Added an answer on May 30, 2026 at 2:19 pm

    Thats because you have different datatype of id column in your child table change it to BIGINT(20)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an auditing trigger that automatically places the time something was updated and
So I've got this database that helps organize information for academic conferences, but we
I have a jqGrid populated with data, but I want to change how this
Is there any way i can implement a zoom listener that can trigger events
The trigger below is delaying my insert response. How can I prevent this? create
If I have a trigger before the update on a table, how can I
I often want to trigger a certain function just once, but I need to
I want to trigger an event that causes the ScrollPane to start scrolling up
We have a scalar function that returns a DateTime. It performs a couple of
I need LINQ to grab a whole table, but this seems not to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.