#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    21
    Rep Power
    0

    Check Constraint in MySQL


    Hi! everyone i have check constraint example like this:

    create table persons
    (
    P_Id int not null,
    LastName varchar(255) not null,
    FirstName varchar(255),
    Address varchar(255),
    City varchar(255),
    CHECK (P_Id>0)
    );

    The above example run successfully but it allow me to input P_Id to 0 which is against the condition. Why it is happening? I take this example from w3school.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2011
    Posts
    118
    Rep Power
    50
    From the MySQL Documentation:

    http://dev.mysql.com/doc/refman/5.6/en/create-table.html

    "The CHECK clause is parsed but ignored by all storage engines."

    It is still worth specifying because (1) it expresses to future developers your intent; (2) future engines may enforce the constraint.

IMN logo majestic logo threadwatch logo seochat tools logo