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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:02:49+00:00 2026-06-14T08:02:49+00:00

Can you help me with this problem? I have two tables in a MySQL

  • 0

Can you help me with this problem? I have two tables in a MySQL database:

ServiceProvider(SPID, Name, ... etc.)
hasTag(SPID, TagID)

Each service provider is supposed to have at least one tag, and a maximum of five tags. The max-constraint is not a problem, but the min-constraint refuses to work properly. I first tried to implement this via assertions, but then I found out, that MySQL does not support assertions. Thus, I wrote the following trigger:

delimiter |

CREATE  TRIGGER MinTags BEFORE INSERT
        ON ServiceProvider
        FOR EACH ROW BEGIN
            IF EXISTS (SELECT SPID FROM ServiceProvider
                       WHERE NOT EXISTS (SELECT DISTINCT SPID FROM hasTag))
            THEN INSERT INTO stop_action VALUES(1, 'Assert Failure');
            END IF;
        END;
|

delimiter ;

The insert of 'Assert Failure' into the stop_action table is only to create a constraint violation, so that the DB would abort the action.

Now, normally, when I insert any value into the ServiceProvider table, without inserting anything in to the hasTag table, I should get an error, right? But, somehow it doesn’t work … I can insert anything I want into the ServiceProvider table, without receiving any kind of error. Do you know, what is wrong with my code?

  • 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-14T08:02:51+00:00Added an answer on June 14, 2026 at 8:02 am

    How about denormalising a tad:

    ALTER TABLE ServiceProvider
      ADD COLUMN TagID1 BIGINT UNSIGNED NOT NULL,
      ADD COLUMN TagID2 BIGINT UNSIGNED NULL,
      ADD COLUMN TagID3 BIGINT UNSIGNED NULL,
      ADD COLUMN TagID4 BIGINT UNSIGNED NULL,
      ADD COLUMN TagID5 BIGINT UNSIGNED NULL;
    

    Include foreign key constraints, if appropriate.

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

Sidebar

Related Questions

can you help me with sql query? I have this problem: I have two
I hope some of you guys can help me with this problem.... I have
Perhaps any of you can help me with this anoying problem. I have long
Dear everybody who can help, I have this PHP > MongoDB problem, I want
I have two tables in a MySQL database, courses and sessions. I'm trying to
I am looking for some help with a MYSQL query. I have two tables,
I have experienced about two times that mysql database crashes and it can not
Hope someone can help me out with this problem I am having. I just
This problem is very strange and I'm hoping someone can help me. For the
I'm hoping someone can help me as I've been stuck on this problem for

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.