DBAsupport.com Forums - Powered by vBulletin
Results 1 to 9 of 9

Thread: check constraint

  1. #1
    Join Date
    May 2002
    Posts
    232
    Hiii friends silly question,
    I am need a check validation for mobilenumber column.
    any user can register to my mobile one through on line,they should enter mobilenumber.
    ex:0162701817
    0162782345 etc.
    Here i want check constraint validation ,any one enter mobilenumber,my check constraint should check the first three numbers 016 only,So i want check validation for this column.
    thanks
    kavitha
    kavitha

  2. #2
    Join Date
    Aug 2001
    Posts
    36
    Hi,

    Try this..

    alter table table_name
    add constraint check_001
    check (mobilenumber like '016%');


  3. #3
    Join Date
    Feb 2000
    Location
    Singapore
    Posts
    1,758
    or...

    Code:
    alter table table_name 
    add constraint check_001 
    check (substr(mobilenumber,1,3) = '016');
    Sanjay

  4. #4
    Join Date
    May 2002
    Posts
    232

    check

    hii thanks,
    and I need 2 validations ,the user must enter with 016 and should enter 10numbers of the mobile.
    like validation one is 016
    second one 0162701817 i.e should enter 10 digits.
    thanks
    kavitha

  5. #5
    Join Date
    Feb 2000
    Location
    Singapore
    Posts
    1,758
    Code:
    alter table table_name 
    add constraint check_002 
    check (length(mobilenumber) = 10);
    Sanjay

  6. #6
    Join Date
    Feb 2002
    Location
    Dallas , Texas
    Posts
    158
    Hi,

    alter table table_name
    add constraint check_001
    check (substr(mobilenumber,1,3) = '016' and length(mobilenumber)=10);

    Are u working as DBA !!!

    Take Care.

  7. #7
    Join Date
    May 2002
    Posts
    35
    kavitha

    how will handle the situation wherein alphanumeric characters are entered into your mobile number.. what if a user enters sone junk /special chars ???


  8. #8
    Join Date
    Feb 2002
    Posts
    267
    anything other than 016 is invalid.....no matter numeric or alphanumeric
    and moreover column datatype in number

  9. #9
    Join Date
    Feb 2002
    Location
    Dallas , Texas
    Posts
    158
    Originally posted by Sonia
    anything other than 016 is invalid.....no matter numeric or alphanumeric
    and moreover column datatype in number
    Hi,

    Sharmila is right..the column is varchar type and not number type.In number type u cannot store value starting from 0.There is no check to see whether a number is entered or a character.

    Take Care.

Posting Permissions

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


Click Here to Expand Forum to Full Width