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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:23:07+00:00 2026-06-14T20:23:07+00:00

Starting with a MySQL trigger like this: delimiter # create trigger comments_after_ins_trig after insert

  • 0

Starting with a MySQL trigger like this:

delimiter #

create trigger comments_after_ins_trig after insert on comments
for each row
begin
  insert into comment_types (comment, user_id) values (new.comment, new.user_id);
end#

Let’s say I wanted to split the inserts into different table, for instance if comment contains a vulgar word (LOCATE('sh**', comment) > 0), instead of comment_types I want to insert into a table called vulgar_comments, if the comment contains the words “thanks” or “nice” insert into nice_comments, etc. Basically how do I make the table name to insert into variable for that trigger?

  • 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-06-14T20:23:08+00:00Added an answer on June 14, 2026 at 8:23 pm

    Try this one, I have tested this and this works on my end:

    delimiter $$
    drop trigger if exists `comments_after_ins_trig`$$
    create trigger `comments_after_ins_trig` after insert on comments
    for each row
    begin
     if(locate("sh**", new.comment) > 0) then
       insert into vulgar_comments(comment, user_id) values (new.comment, new.user_id);
     else
       insert into comment_types (comment, user_id) values (new.comment, new.user_id);
     end if;
    end$$
    
    delimiter ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am just starting with JBDC. I need to create an Java/MySQL insert statement
I'm starting on a new iPhone project, and this application mostly relies on MySQL.
I am just starting to use html, php, and mysql. I've successfully logged into
Starting a new project I'd like to use Hibernate annotations with MySQL instead of
In MySQL, how can I retrieve ALL rows in a table, starting from row
I am starting with the answer on this page PHP/mySQL - how to fetch
Hi everyone I'm trying to insert 600 rows in a MYSQL table starting from
After 4 years of using MySql for most php projects, I'm starting to realize
I am starting to use MySQL with JDBC. Class.forName(com.mysql.jdbc.Driver); conn = DriverManager.getConnection(jdbc:mysql:///x, x, x);
I'm starting to develop an application using MySQL and although I've developed apps before

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.