Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2009
    Posts
    20

    Unanswered: Simple Questions

    Hi...
    I am new in SQL Server and general in databases.... i have 3 Questions

    1) What is the meaning of using Select Distinct

    2)How i will make my field save strings with empty spaces like (THomas Leite) or with no empty spaces(THomasLeite)

    3)How i will make one field for example(Titles) not accept 2 times the same value

  2. #2
    Join Date
    Jun 2004
    Location
    Long Island
    Posts
    696
    Quote Originally Posted by ThomasKain24
    Hi...
    I am new in SQL Server and general in databases.... i have 3 Questions

    1) What is the meaning of using Select Distinct

    2)How i will make my field save strings with empty spaces like (THomas Leite) or with no empty spaces(THomasLeite)

    3)How i will make one field for example(Titles) not accept 2 times the same value
    1. Selecting only unique values, whether 1 or more exist for that value
    2. replace(fieldname,' ','')
    3. unique/primary key

  3. #3
    Join Date
    Mar 2009
    Posts
    20
    Ok i got it for the first.....
    In the second question i mean how the user when he type THomas Leite the field will take (ThomasLeite) and how will be normal and save (Thomas Leite).
    In the third question i see my table and i can put only primary key . I put the primary key in BooksId but i want the Title of the books not be the same

  4. #4
    Join Date
    Apr 2008
    Location
    Iasi, Romania
    Posts
    561
    Provided Answers: 2
    For 3:
    ALTER TABLE yourTable ADD CONSTRAINT constraintName UNIQUE(Title)

  5. #5
    Join Date
    Apr 2008
    Location
    Iasi, Romania
    Posts
    561
    Provided Answers: 2
    For 2:
    Usualy, a CHAR/VARCHAR column stores exactly what user "types". If you want to remove the white spaces, I think you need a trigger.

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    users typically don't "type" right into a database column

    there's usually a front-end application, like a php script

    that's where you should be stripping out the blanks

    oh, and incidentally, that's also where you stop things like "little bobby tables"

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

  7. #7
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,800
    Provided Answers: 11
    Other than that, how are you doing in the class?

  8. #8
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Quote Originally Posted by r937
    oh, and incidentally, that's also where you stop things like "little bobby tables"
    +10 kudos points
    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
  •