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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:17:21+00:00 2026-06-12T14:17:21+00:00

I feel embarrassed that I have to come and ask for help with this,

  • 0

I feel embarrassed that I have to come and ask for help with this, but as surely many before me have learned, it seems mySQL syntax error messages are about as useful as a pope hat on a grizzly bear. Attached is my first attempt at writing a trigger for a car company database. The table, can_lease, relates the id of an employee and the id of a car model. The trigger is expected to enforce two rules: 1) there can be at most 10 car models associated with 1 employee, and 2) the employee must be of type leasing (there is a column ‘leasing’ which must equal ‘Y’).

So the goal is for the trigger to catch violations of this rule and send a signal and a message explaining the violation. I’m simply not sure what the errors are, but I will attach the relevant error messages as well.

create procedure can_lease_check (eid int)
begin
        declare can_lease_too_many_models condition for sqlstate '90001';
        if ((select count(rent_model_id) from can_lease where emp_id = eid) >= 10)
        then signal sqlstate '90001' set message_text = 'employee can lease at most 10 rent models.';

        declare can_lease_not_leaser for sqlstate '90002';                                                                                           
        if not (select leasing from employer where employer.emp_id = eid) == 'Y'                                                                     
        then signal sqlstate '90002' set message_text = 'employee must be of type "leasing"';
end;

delimiter $$
create trigger can_lease_insert_trigger
after insert on can_lease
for each row begin
    call can_lease_check(new.emp_id);
end;
$$

create trigger can_lease_update_trigger
after update on can_lease
for each row begin
    call can_lease_check(new.emp_id);
end;
$$

And here are the error messages:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'if ((select count(rent_model_id) from can_lease where emp_id = eid) >= 10)
    then' at line 1
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'end' at line 1

Thank you for your help! I would also appreciate any advice one has for debugging this sort of thing in general. Coming from gcc telling me at least something about why my code is wrong, this is a very foreign process!

EDIT: I realize that I should have moved the delimiter change up to above the procedure as well. I don’t get it, but that removes all but one of the errors. Currently, the error is

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'if (select count(rent_model_id) from can_lease where emp_id = eid) == 10
    then s' at line 4
  • 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-12T14:17:22+00:00Added an answer on June 12, 2026 at 2:17 pm

    The semicolons (;) between the first begin and end keywords are the culprits. Just enclose your original create block with a DELIMITER, as follows. I use # as the delimiter in my example, and I recognize that you use $$, though there will be no resulting difference.

    DELIMITER #
    create procedure can_lease_check (eid int)
    begin
        declare can_lease_too_many_models condition for sqlstate '90001';
        if ((select count(rent_model_id) from can_lease where emp_id = eid) >= 10)
        then signal sqlstate '90001' set message_text = 'employee can lease at most 10 rent models.';
    
        declare can_lease_not_leaser for sqlstate '90002';                                                                                           
        if not (select leasing from employer where employer.emp_id = eid) == 'Y'                                                                     
        then signal sqlstate '90002' set message_text = 'employee must be of type "leasing"';
    end#
    

    Also, there will be no difference if you end it like I did (end#), or like you did, with the semicolon after the end keyword:

    end;
    #
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably trivial - I almost feel embarrassed to ask, but I am
This is a dumb question and I feel embarrassed to ask it, but I'm
I feel embarrassed asking this, but it seems like something I need to understand:
I'm a little embarrassed to ask this as I ought to know better, but
I feel like this question has been asked before but the answers seem pretty
I feel like this is a really simple question, but I need help figuring
I feel embarrassed to ask: but what is the right combination of annotations for
I feel embarrassed asking this question, but I've spent the last half an hour
I feel dumb for having to ask this but I cannot find how to
I feel embarrassed to ask this question as I feel like I should already

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.