Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Join Date
    Feb 2008
    Posts
    5

    Unanswered: Is it possible to to have a primary key that...

    Hi all,

    Is it possible to have a primary key for SQL or Oracle or jet to have an alpanumeric beginning?

    for example
    1st District as a primary key

    The statement is:
    SELECT itemid FROM MASecurity WHERE userid=%d

    Thanks,
    Jj

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    The only requirement for being a primary key is that it must be comparable. If you can tell for sure that values of the data type are equal or not, then they can be primary keys. Through SQL 2005, the only thing this excludes is NULL values (primary keys can not be NULL-able).

    -PatP

  3. #3
    Join Date
    Feb 2008
    Posts
    5
    Hi,

    thanks, how about a table? can a table name have an alphanumeric in the beginning? Like 1Table?

    thanks,
    Jj

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    It depends, but usually.

    -PatP

  5. #5
    Join Date
    Feb 2008
    Posts
    5
    Quote Originally Posted by Pat Phelan
    It depends, but usually.

    -PatP
    Thanks Pat much appreciated

  6. #6
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Quote Originally Posted by Pat Phelan
    The only requirement for being a primary key is that it must be comparable.
    Nevermind........
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  7. #7
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    I thought that all objects had to start with an alpha character; thus making "1table" invalid?
    George
    Home | Blog

  8. #8
    Join Date
    Dec 2007
    Posts
    253
    Code:
    SQL> create table "123" as select * from employees;
    
    Table created.
    
    SQL> create table 123 as select * from employees;
    create table 123 as select * from employees
                 *
    ERROR at line 1:
    ORA-00903: invalid table name
    It can be done. You can also stick your fingers in a plug socket. Doesn't make it a good idea.

  9. #9
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Don't mix up could and should

    You can have numerics at the start of the object name but you then need to refer to it using square brackets:
    [1table]

  10. #10
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    ^^^ Like what he said

  11. #11
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    -- all object names should use only whitespace
    create database [ ]
    go
    use [ ]
    go
    create table [ ] ([ ] int not null primary key)
    go


  12. #12
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Not enough indirection layers for my taste
    http://www.dbforums.com/showpost.php...4&postcount=18

  13. #13
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by pablolee
    You can also stick your fingers in a plug socket. Doesn't make it a good idea.
    quote of the week

    (but it's still early)

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

  14. #14
    Join Date
    Dec 2007
    Posts
    253
    LOL, Thanks, I heard it from an Oracle instructor once and liked it.

  15. #15
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by pootle flump
    Not enough indirection layers for my taste
    http://www.dbforums.com/showpost.php...4&postcount=18
    very "Obsucatory" indeed
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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