Results 1 to 11 of 11
  1. #1
    Join Date
    Jun 2007
    Posts
    197

    Smile Unanswered: restrict blank spcae in database

    Hi ,
    How can we restrict blank spaces such as we can restrict null by using not null

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Does MySQL support CHECK constraints? Memory says "not exactly"... This would be my preferred method.
    George
    Home | Blog

  3. #3
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Quote Originally Posted by georgev
    Does MySQL support CHECK constraints?
    No, not at all.

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Would I be right in thinking that it doesn't mind if you try and add one, it just doesn't do anything with it? Almost a forward-compatability (ha!) inclusion...
    George
    Home | Blog

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    no you would not
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10

  7. #7
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    i sit corrected

    my humblest apologies
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  8. #8
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Ok, so without CHECK constraints, my only other offering would be to put the logic in all your sprocs that touch the data.

    Can you explain why you want to do this?
    George
    Home | Blog

  9. #9
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    "sprocs" is such a microsoftian word

    how do you know he's using spocs in MySQL?

    and how would this prevent entering "blank spaces" (as though there were any other kind of spaces) through plain old DML?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  10. #10
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Lol, ok Rudy.

    I don't know the OP is using sprocs (or Stored Procedures/Routines if you prefer), so I should have used a more blanket statement.

    Your data access layer will have to handle blank strings for you.

    In Microsofts SQL Server there is a function called NullIf() which I would use in this scenario to "convert" blank strings to NULL values. Whether this particular function exists in MySQL is a different question and not one I able to answer at this juncture (dev.mysql just won't load at this location!)
    George
    Home | Blog

  11. #11
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    George
    Home | Blog

Posting Permissions

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