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 4060592
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:21:28+00:00 2026-05-20T15:21:28+00:00

I am developing a MySQL database using Workbench. I want two send two fields

  • 0

I am developing a MySQL database using Workbench. I want two send two fields from a newly created record to another table. I would then like to update the original table with newly created data from the second table. I was looking to implement this with triggers, unless there is a better way of course 🙂 My attempt was a fail when I went to upload it(see below)

Specifically, I would like tc_Event to send the ID & tc_EventTags_ID to tc_EventTags to fill in tc_Tag_ID & tc_Event_ID. Afterwards I want the ID of tc_EventTags sent back to tc_Event to the tc_EventTags_ID field.

Thanks for any help.

-- -----------------------------------------------------
-- Table `mcontest`.`tc_EventTags`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mcontest`.`tc_EventTags` (
  `ID` INT NOT NULL AUTO_INCREMENT ,
  `tc_Tag_ID` INT NOT NULL ,
  `tc_Event_ID` INT NOT NULL ,
  PRIMARY KEY (`ID`) ,
  INDEX `fk_tc_EventTags_tc_Tag1` (`tc_Tag_ID` ASC) ,
  INDEX `fk_tc_EventTags_tc_Event1` (`tc_Event_ID` ASC) ,
  CONSTRAINT `fk_tc_EventTags_tc_Tag1`
    FOREIGN KEY (`tc_Tag_ID` )
    REFERENCES `mcontest`.`tc_Tag` (`ID` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_tc_EventTags_tc_Event1`
    FOREIGN KEY (`tc_Event_ID` )
    REFERENCES `mcontest`.`tc_Event` (`ID` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = MyISAM;

-- -----------------------------------------------------
-- Table `mcontest`.`tc_Event`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mcontest`.`tc_Event` (
  `ID` INT NOT NULL AUTO_INCREMENT ,
  `date` DATE NOT NULL ,
  `time` TIME NOT NULL ,
  `location` VARCHAR(45) NOT NULL ,
  `description` VARCHAR(45) NOT NULL ,
  `tc_EventTags_ID` INT NULL ,
  `tc_Orgs_ID` INT NOT NULL ,
  `tc_PersonEvent_ID` INT NOT NULL ,
  PRIMARY KEY (`ID`) ,
  INDEX `fk_tc_Event_tc_EventTags1` (`tc_EventTags_ID` ASC) ,
  INDEX `fk_tc_Event_tc_Orgs1` (`tc_Orgs_ID` ASC) ,
  INDEX `fk_tc_Event_tc_PersonEvent1` (`tc_PersonEvent_ID` ASC) ,
  CONSTRAINT `fk_tc_Event_tc_EventTags1`
    FOREIGN KEY (`tc_EventTags_ID` )
    REFERENCES `mcontest`.`tc_EventTags` (`ID` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_tc_Event_tc_Orgs1`
    FOREIGN KEY (`tc_Orgs_ID` )
    REFERENCES `mcontest`.`tc_Orgs` (`ID` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_tc_Event_tc_PersonEvent1`
    FOREIGN KEY (`tc_PersonEvent_ID` )
    REFERENCES `mcontest`.`tc_PersonEvent` (`ID` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = MyISAM;


    USE `mcontest`;

    DELIMITER $$
    USE `mcontest`$$


    CREATE TRIGGER eventTag_Trigger
    AFTER insert ON tc_Event

    FOR EACH ROW BEGIN 
    INSERT INTO tc_EventTags values('',NEW.tc_Event_ID);
    END;


    END$$


    DELIMITER ;


    SET SQL_MODE=@OLD_SQL_MODE;
    SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
    SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
  • 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-20T15:21:29+00:00Added an answer on May 20, 2026 at 3:21 pm

    Why have put a tc_EventTags_ID in table tc_Event? What is the logic behind that?

    I mean that the relationship between the 2 tables would be (I guess): 1 Event – many EventTags. This is already achieved by the tc_EventTags.tc_Event_ID which is a Foreign Key to tc_Event.

    To answer your question:

    As it is now, the Trigger tries for every row inserted in table Event, to add a row in table EventTag. But it will fail for 2 reasons:

    1. EventTag has 2 Constraints (Foreign keys) which have to be fulfilled for the triggered insert to succeed. So, tc_Event_ID is ok but tc_Tag_ID has to be NOT NULL and reference the Tag table but the value you supply, '', probably is not in table Tag.

    EDIT: the value you supply, '', is also a CHAR while it should be INT.

    1. But trigger will probably not be started at all, since every time you insert a row in table Event, those constraints have to be fulfilled and one of them is the tc_EventTags_ID which references EventTag table. But EventTag table is empty. Do you see the circular logic here?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently developing a website which stores bookmarks in a MySQL database using PHP
I am developing a Python web app using sqlalchemy to communicate with mysql database.
My team is developing a large java application which extensively queries a MySQL database
I am developing a PHP/MySQL application using vertrigoserver. I need to enter the German
I am developing a hibernate application that connects to a MySQL database. The customers
I'm developing a class to manage the operations on a Mysql database. I have
I am developing a script in PHP for uploading files to a MySQL database.
I'm developing a high-volume web application, where part of it is a MySQL database
i am developing window application using visual studio and c# i want to insert
Developing websites are time-consuming. To improve productivity, I would code a prototype to show

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.