Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    mysql primary key

    A primary key in ORACLE implies unique and not null, implies u cannot leave the column empty during an insert. In mysql, a column defined as a primary key accepts if nothing is inserting into that column during an insert, for the first time. The next time the same is performed(ie., leaving the primary key column empty), it is violation of primary key constraint.
    That is, mysql's definition of primary key implies only unique but not NOT NULL. Wat do i do to have a column both unique and notnull?

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    When you leave it out an empty string is entered. That is not the same thing at all as NULL. so even if you declared it as a NOT NULL column, you can still leave it empty on the first insertion.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Adirondacks
    Posts
    516
    Thanks
    4
    Thanked 4 Times in 4 Posts
    when I create a table in phpmyadmin I'd swear one of the choices in the pull down menu is "not null"
    Maybe I'm thinking of something else

  • #4
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    there is a choice of NOT NULL because you can make a column NOT NULL. and you can create the column as UNIQUE.

    An empty string can still be entered in the table once because an empty string isn't NULL. On the second insertion of an empty string though you won't be able to do it because an empty string exists.


  •  

    Posting Permissions

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