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

  • Home
  • SEARCH
  • 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 8397771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:52:40+00:00 2026-06-09T20:52:40+00:00

I’d like to create a before insert trigger that uses new values to insert

  • 0

I’d like to create a before insert trigger that uses new values to insert to check if the trigger should let the insert happend or stop it following some conditions. I can’t really find the right syntax for that trigger but here is the pseudo code that is explicit enough :

CREATE TRIGGER my_first_trigger BEFORE INSERT COMMENT VALUES(comment, #commentPIID, #commentUserID)

FOR EACH ROW
BEGIN
IF
(SELECT USER.ID
FROM USER LEFT JOIN PI_REMINDER ON  PI_REMINDER.userID == USER.ID
WHERE PI_REMINDER.ID == commentPIID && USER.ID == commentUserID) IS NOT NULL)
OR
 ((SELECT userID
FROM pishared
WHERE PIID == commentPIID && userID ==commentUserID && acceot == 1) IS NOT NULL)

THEN
INSERT INTO COMMENT VALUES(comment, #commentPIID, #commentUserID)

END IF;
END;

Could someone tell me the right syntax to use in that pseudo code case?

  • 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-09T20:52:41+00:00Added an answer on June 9, 2026 at 8:52 pm

    As I understand the trigger should restrict some insertions, in this case you can check the condition and then throw an error to escape from inseкtion. The errors in MySQL can be generated using SIGNAL statement in MySQL 5.5 or calling unknown procedure (e.g. CALL proc100).

    I have used COUNT(*) function to know if there are corresponding records in another tables. And one more thing – there were some syntax errors in your trigger, I have correct them.

    So, the trigger may look like this –

    CREATE TRIGGER my_first_trigger BEFORE INSERT ON COMMENT
    FOR EACH ROW
    BEGIN
      SET @cnt = NULL;
    
      SELECT COUNT(*) INTO @cnt FROM USER
        LEFT JOIN PI_REMINDER
          ON PI_REMINDER.userID = USER.ID
      WHERE
        PI_REMINDER.ID = NEW.commentPIID AND USER.ID = NEW.commentUserID;
    
      IF @cnt = 0 THEN
        SIGNAL SQLSTATE '02000';
      END IF;
    
      SELECT COUNT(*) INTO @cnt FROM pishared
      WHERE
        PIID = NEW.commentPIID AND userID = NEW.commentUserID AND acceot = 1;
    
      IF @cnt = 0 THEN
        SIGNAL SQLSTATE '02000';
      END IF;
    
    END;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I would like to run a str_replace or preg_replace which looks for certain words

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.