MYSQL Constraint Check

Posted on 2009-04-23
Last Modified: 2012-06-27
I've been trying to get the CHECK working in MYSQL and from what I am reading it's not yet been implemented.

How would I go about getting this to work:

ALTER TABLE contracts
ADD CONSTRAINT contract_check CHECK (value >500 )
Question by:directxBOB
    LVL 39

    Expert Comment

    by:Roger Baklund
    As you have allready read, it is not implemented, alas, you can not get it to work.

    Author Comment

    is there any form of work around? Perhaps a trigger mechanism.
    LVL 39

    Accepted Solution

    Yes, you could implement triggers to handle this. You need BEFORE INSERT and BEFORE UPDATE triggers. Something like this:
    CREATE TRIGGER contracts_ins_trigger BEFORE INSERT on contracts
      FOR EACH ROW set new.value=if(new.value<500,500,new.value); 
    CREATE TRIGGER contracts_upd_trigger BEFORE UPDATE on contracts
      FOR EACH ROW set new.value=if(new.value<500,500,new.value); 

    Open in new window


    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
    Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now