Results 1 to 12 of 12

Thread: Please help

  1. #1
    Join Date
    Nov 2003
    Posts
    6

    Red face Unanswered: Please help

    Why doesn't it work ??

    ALTER TABLE Client ADD ( CONSTRAINT ctr_cl_mail CHECK (email LIKE '%@%.%'));

    AND


    ALTER TABLE Client ADD ( CONSTRAINT ctr_client_cp CHECK ( cp LIKE '[0-9][0-9][0-9][0-9][0-9]' ) );
    for the postal code of my client.... like 78000 for FRANCE (I'm French !)


    I thought it could be good but when I want to insert a new value in Client table, I have a constraint violation even if I've entered 78000 for the postal code in my client...

    Thank to help me...

  2. #2
    Join Date
    Nov 2003
    Posts
    6

    Re: Please help

    Who can help me ??? it's very important for me, it's for a project for college

    je vois pas pk ca marche pas!!!

  3. #3
    Join Date
    Oct 2003
    Location
    St.Louis,MO
    Posts
    120

    Re: Please help

    Originally posted by totorob
    Why doesn't it work ??

    ALTER TABLE Client ADD ( CONSTRAINT ctr_cl_mail CHECK (email LIKE '%@%.%'));

    AND


    ALTER TABLE Client ADD ( CONSTRAINT ctr_client_cp CHECK ( cp LIKE '[0-9][0-9][0-9][0-9][0-9]' ) );
    for the postal code of my client.... like 78000 for FRANCE (I'm French !)


    I thought it could be good but when I want to insert a new value in Client table, I have a constraint violation even if I've entered 78000 for the postal code in my client...

    Thank to help me...
    try
    ALTER TABLE table_name ADD CONSTRAINT constraint_name CHECK (check_condition)

  4. #4
    Join Date
    Oct 2003
    Location
    St.Louis,MO
    Posts
    120

    Re: Please help

    Originally posted by totorob
    Why doesn't it work ??

    ALTER TABLE Client ADD ( CONSTRAINT ctr_cl_mail CHECK (email LIKE '%@%.%'));

    AND


    ALTER TABLE Client ADD ( CONSTRAINT ctr_client_cp CHECK ( cp LIKE '[0-9][0-9][0-9][0-9][0-9]' ) );
    for the postal code of my client.... like 78000 for FRANCE (I'm French !)


    I thought it could be good but when I want to insert a new value in Client table, I have a constraint violation even if I've entered 78000 for the postal code in my client...

    Thank to help me...
    looking at your postal code example it looks like
    ALTER TABLE table_name ADD CONSTRAINT constraint_name CHECK (cp between 00000 and 99999)
    would work better, maybe, I didn't try it.

  5. #5
    Join Date
    Nov 2003
    Posts
    6

    Unhappy Re: Please help

    Originally posted by tlael
    try
    ALTER TABLE table_name ADD CONSTRAINT constraint_name CHECK (check_condition)
    Is it different of what I've done except the brackets ???

    There is no errors when I creat the constraint but when i want to add a client, the constrainst always appear... even if I typed 78000 or abcde for the postal code....

    It's qute strange ???

  6. #6
    Join Date
    Oct 2003
    Location
    St.Louis,MO
    Posts
    120

    Re: Please help

    Originally posted by totorob
    Is it different of what I've done except the brackets ???

    There is no errors when I creat the constraint but when i want to add a client, the constrainst always appear... even if I typed 78000 or abcde for the postal code....

    It's qute strange ???
    The like clause kinda throws me.
    you used LIKE with no %% and you enclosed the numbers in quotes.

    don't forget to drop the original constraint!

  7. #7
    Join Date
    Nov 2003
    Posts
    6

    Re: Please help

    Originally posted by tlael
    looking at your postal code example it looks like
    ALTER TABLE table_name ADD CONSTRAINT constraint_name CHECK (cp between 00000 and 99999)
    would work better, maybe, I didn't try it.
    But I my postal code is a varchar(5):
    If I have the postal code 08000 with number(5), the first '0' doen't appear... so I have made the postal code with varchar(5)...

  8. #8
    Join Date
    Oct 2003
    Location
    St.Louis,MO
    Posts
    120

    Re: Please help

    Originally posted by totorob
    But I my postal code is a varchar(5):
    If I have the postal code 08000 with number(5), the first '0' doen't appear... so I have made the postal code with varchar(5)...
    If that is the case then you must put quotes around the numbers in the between clause I wrote

  9. #9
    Join Date
    Oct 2003
    Location
    St.Louis,MO
    Posts
    120

    Re: Please help

    Originally posted by tlael
    If that is the case then you must put quotes around the numbers in the between clause I wrote
    ALTER TABLE table_name ADD CONSTRAINT constraint_name CHECK (cp between '00000' and '99999')

  10. #10
    Join Date
    Nov 2003
    Posts
    6

    Re: Please help

    Originally posted by tlael
    ALTER TABLE table_name ADD CONSTRAINT constraint_name CHECK (cp between '00000' and '99999')
    YES !!! you're right..... Thanks a lot, sorry for my poor english, I'm not very ggod at english.... I hope I can be understood....

    thanks

  11. #11
    Join Date
    Oct 2003
    Location
    St.Louis,MO
    Posts
    120

    Re: Please help

    Originally posted by totorob
    YES !!! you're right..... Thanks a lot, sorry for my poor english, I'm not very ggod at english.... I hope I can be understood....

    thanks
    Pardon my French:
    Aucun souci, ne m'envoient juste une bouteille de Pinot Gris !
    Last edited by tlael; 11-04-03 at 18:59.

  12. #12
    Join Date
    Nov 2003
    Posts
    6

    Re: Please help

    Originally posted by tlael
    Pardon my French:
    Aucun souci, ne m'envoient juste une bouteille de Pinot Gris !
    LOL, no pb, I send you a bottle of pineau !!! lol ciao

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •