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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:46:14+00:00 2026-05-20T02:46:14+00:00

Let’s consider table Video( IDvideo(PK), Date, Description, User ) with mysql I have no

  • 0

Let’s consider table

Video(
    IDvideo(PK),
    Date,
    Description,
    User
)

with mysql I have no way of writing assertions.
Is it possible to simulate the following assertion using one or more triggers ?

create assertion asser1  
check (0 = 
    ( select count(*)  
      from Video  
      where Date >= DATE_SUB(current_date(),INTERVAL  1 YEAR ) 
          && Date<=current_date()  
      group by User   
      having count(*) > 200
    )
)

how should I write 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-05-20T02:46:15+00:00Added an answer on May 20, 2026 at 2:46 am

    Well, the problem is that MySQL doesn’t have an equivalent of a STOP ACTION command. So basically, the work arounds are quite dirty:

    One way is that you can violate a constraint inside the trigger to bubble an error and cancel the insert:

    CREATE TABLE stop_action (
        id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
        name VARCHAR(35),
        UNIQUE KEY (id, name)
    );
    INSERT INTO stop_action (1, 'Assert Failure');
    

    Then, in the trigger, just try to:

    INSERT INTO stop_action (1, 'Assert Failure');
    

    The benefit of that, is that the error that’s returned will be a duplicate key error, and the text will include “Assert Failure”.

    So then your trigger would become:

    delimiter |
    
    CREATE TRIGGER asser1_before BEFORE INSERT ON test1
      FOR EACH ROW BEGIN
        SELECT count(*) INTO test FROM (select count(*)
              from Video  
              where Date >= DATE_SUB(current_date(),INTERVAL  1 YEAR ) 
                && Date<=current_date()  
              group by User   
              having count(*) > 200);
        IF test != 0 THEN
            INSERT INTO stop_action (1, 'Assert Failure');
        END IF;
      END;
    |
    
    delimiter ;
    

    Now, you’d need to do this before UPDATE as well, otherwise you could update the date into an invalid state. But otherwise, that should at least get you started…

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

Sidebar

Related Questions

Let us consider a user table: Username,email1,email2 Now, I want to make sure that
In setting up a MySQL database, consider that I have a table of products
Consider this problem: I have a program which should fetch (let's say) 100 records
Let's consider we have QWidget that contains QTableWidget (only). So we want to resize
Consider the following table: People FirstName nvarchar(50) LastName nvarchar(50) Let's assume for the moment
Is it possible to animate the replacement of a class in javascript? Let's consider
Well guys, I have three tables here, menu, user and access. For simplifying let's
This question requires some hypothetical background. Let's consider an employee table that has columns
I have the following problem: Let's consider we have #define SET callMe #define COLUMN(x)
Let's consider this table: [name] [type] Ken Anderson 1 John Smith 2 Bill Anderson

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.