WHY CHECK CONSTRINT IS NOT WORKING

  • HI ALL,

    I CREATED A TABLE AND APPLIED CHECK CONSTRAINT USING IN AND LATER I AM ENTERING DATA WHY CHECK CONSTRAINT IS ACCEPTING ALL THE INSERT STATEMENTS.

    CREATE TABLE TEST1(SNO INT,

    NAME VARCHAR(20),

    STATUS CHAR(1) CONSTRAINT CHK_1 CHECK (STATUS IN (NULL,'N','Y')) DEFAULT NULL)

    INSERT INTO TEST1 VALUES(1,'ABC','')

    INSERT INTO TEST1(SNO,NAME) VALUES(1,'ABC')

    INSERT INTO TEST1(SNO,NAME,STATUS) VALUES (1,'ABC','T')

    THANKS,

    SAI

  • PlEaSe HaVe A lOoK tO bOl FoR iN sTaTeMeNt. YoU cAnNoT uSe ThIs FoR nUlL vAlUeS. sO tRy ThIs:

    😀

    CREATE TABLE TEST1

    (

    SNO INT,

    NAME VARCHAR(20),

    STATUS CHAR(1)

    CONSTRAINT CHK_1

    CHECK (STATUS IS NULL OR STATUS IN ('N','Y'))

    DEFAULT NULL

    )

    INSERT INTO TEST1 VALUES(1,'ABC','')

    INSERT INTO TEST1(SNO,NAME) VALUES(1,'ABC')

    INSERT INTO TEST1(SNO,NAME,STATUS) VALUES (1,'ABC','T')

    SELECT * FROM TEST1

    Flo

  • Ow. This thread hurts my eyes and my ears! 😛

  • saidwarak01 (6/24/2009)


    HI ALL,

    I CREATED A TABLE AND APPLIED CHECK CONSTRAINT USING IN AND LATER I AM ENTERING DATA WHY CHECK CONSTRAINT IS ACCEPTING ALL THE INSERT STATEMENTS.

    Please don't post in all caps. It's the online-equivalent of shouting at someone.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Gail and Paul,

    ThAnKs FoR cLaRiFyInG mY pOsT!

  • Hi,

    My simple advise to moderators is any kind of post whether it is simple or tuff. It should be properly handled by giving some solution. This forum is for helping others with your extra knowledge and extra skills and not to hurt any body by typing CAPS or something else.

    Thanks,

    sai

  • saidwarak01 (6/25/2009)


    My simple advise to moderators is any kind of post whether it is simple or tuff. It should be properly handled by giving some solution.

    And it has been. See Flo's answer. If that hasn't solved your problem, say so and explain what's missing.

    p.s. no moderators have posted in this thread so far.

    This forum is for helping others with your extra knowledge and extra skills and not to hurt any body by typing CAPS or something else.

    All caps is very hard to read. If a question's hard to read I'm likely to skip it and go elsewhere. You're welcome to post anyway you want, but the harder it is to read and/or answer, the less likely someone is to answer it. Remember we're doing this in our spare time.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • sai,

    saidwarak01 (6/25/2009)


    It should be properly handled by giving some solution.

    I gave you a solution. If it doesn't work or you have any questions about let me know.

    ...and not to hurt any body by typing CAPS or something else.

    As Gail wrote, writing in CAPS is like screaming in online-forums.

    Flo

  • saidwarak01 (6/25/2009)


    My simple advise to moderators is any kind of post whether it is simple or tuff. It should be properly handled by giving some solution. This forum is for helping others with your extra knowledge and extra skills and not to hurt any body by typing CAPS or something else.

    If you are unhappy with the posted solution or comments, please accept a full refund with my apologies.

    LOL

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply