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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:39:56+00:00 2026-05-15T13:39:56+00:00

Do you know how to rewrite these this query in MySQL ? I can’t

  • 0

Do you know how to rewrite these this query in MySQL ?
I can’t find Identity insert, I can’t find any try catch,
I don’t understand it.

CREATE TRIGGER T1 ON DB1.dbo.A
AFTER INSERT AS

 BEGIN TRY

  SET IDENTITY_INSERT DB2.dbo.B ON
   INSERT INTO dbo.B(id, text) SELECT A.id,A.text FROM dbo.A INNER JOIN inserted I ON I.id = A.id
  SET IDENTITY_INSERT DB2.dbo.B OFF

  SET IDENTITY_INSERT DB2.dbo.D ON      
   INSERT INTO dbo.D(id, text) SELECT A.id,A.text FROM dbo.A INNER JOIN inserted I ON I.id = A.id     
  SET IDENTITY_INSERT DB2.dbo.D OFF

 END TRY
 BEGIN CATCH

  ROLLBACK TRANSACTION

  SET IDENTITY_INSERT DB2.dbo.B OFF
  SET IDENTITY_INSERT DB2.dbo.D OFF
 END CATCH

GO
  • 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-15T13:39:57+00:00Added an answer on May 15, 2026 at 1:39 pm

    MySQL triggers have implicit transaction support, so the trigger cannot use statements that explicitly or implicitly begin or end a transaction such as START TRANSACTION, COMMIT, or ROLLBACK.

    It is not necessary in MySQL to enable the insertion of values into primary key columns – this is already allowed. You can, however, toggle foreign key constraint checking and unique index checking:

    http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html
    http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_unique_checks

    A common way to do this is to store the existing values in user variables, change the settings, then restore the settings after your script is complete:

    SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
    SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
    
    -- Your SQL statements here.
    
    SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
    SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
    

    I’m not sure why you would need to do that in your trigger, so your MySQL trigger would look something like this:

    DELIMITER |
    CREATE TRIGGER T1 AFTER INSERT ON A FOR EACH ROW
    BEGIN
    
        INSERT INTO B (id, text) VALUES (NEW.id, NEW.text);
    
        INSERT INTO C (id, text) VALUES (NEW.id, NEW.text);
    
    END;|
    DELIMITER ;
    

    Here’s the results of a quick test:

    CREATE TABLE `A` (
      `id` int(11) NOT NULL auto_increment,
      `text` varchar(255) default NULL,
      PRIMARY KEY  (`id`)
    );
    
    CREATE TABLE `B` (
      `id` int(11) NOT NULL auto_increment,
      `text` varchar(255) default NULL,
      PRIMARY KEY  (`id`)
    );
    
    CREATE TABLE `C` (
      `id` int(11) NOT NULL auto_increment,
      `text` varchar(255) default NULL,
      PRIMARY KEY  (`id`)
    );
    
    DELIMITER |
    CREATE TRIGGER T1 AFTER INSERT ON A FOR EACH ROW
    BEGIN
    
        INSERT INTO B (id, text) VALUES (NEW.id, NEW.text);
    
        INSERT INTO C (id, text) VALUES (NEW.id, NEW.text);
    
    END;|
    DELIMITER ;
    
    INSERT INTO `A` (id, text) VALUES (1, 'Line 1');
    INSERT INTO `A` (id, text) VALUES (2, 'Line 3');
    INSERT INTO `A` (id, text) VALUES (3, 'Line 3');
    
    SELECT * FROM `A`;
    +----+--------+
    | id | text   |
    +----+--------+
    |  1 | Line 1 |
    |  2 | Line 3 |
    |  3 | Line 3 |
    +----+--------+
    
    SELECT * FROM `B`;
    +----+--------+
    | id | text   |
    +----+--------+
    |  1 | Line 1 |
    |  2 | Line 3 |
    |  3 | Line 3 |
    +----+--------+
    
    SELECT * FROM `C`;
    +----+--------+
    | id | text   |
    +----+--------+
    |  1 | Line 1 |
    |  2 | Line 3 |
    |  3 | Line 3 |
    +----+--------+
    

    If you want something similar to TRY … CATCH, you’ll need to use handlers instead:
    http://dev.mysql.com/doc/refman/5.1/en/declare-handler.html

    Here’s the documentation on MySQL triggers:
    http://dev.mysql.com/doc/refman/5.1/en/commit.html

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

Sidebar

Related Questions

In JDBC I can use question marks for query parameters, like this: SELECT *
I have a long running query that returns a large data set. This query
I've got a 2.0 server control that uses a dynamic query roughly in the
Or any viable workaround. So, imagine a Master page that implements IFooMaster with a
I am starting to use decorators in PHP more often these days to modify
I have a form like this: <form id=form_main name=form_main action=/search/ target=iframe001 method=get onSubmit=reset_and_subm();> Enter
We are in the process of planning for a rewrite of one of our
Imagine a table emp : CREATE TABLE emp ( id NUMBER , name VARCHAR
We're changing the way users embed images in their blogs, but I need to
I worked out an XSL template that rewrites all hyperlinks on an HTML page,

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.