Results 1 to 7 of 7

Thread: mysql issue

  1. #1
    Join Date
    Apr 2005
    Location
    Turkey
    Beans
    353
    Distro
    Ubuntu Development Release

    mysql issue

    CREATE TABLE `customer` (
    `customer_id` int(8) NOT NULL auto_increment,
    `username` varchar(20) collate ascii_bin NOT NULL default '',
    `first_name` varchar(15) collate ascii_bin NOT NULL default '',
    `last_name` varchar(30) collate ascii_bin NOT NULL default '',
    `DOB` date NOT NULL default '0000-00-00',
    `address_line1` varchar(20) collate ascii_bin NOT NULL default '',
    `adress_line2` v

    im trying to get the username table to be authentic, ie
    i noticed i would have a problem with username duplication

    what do i do to do the table or the db to make it spit and error out if a username is used twice..?
    ____________________________
    Mahir Sayar
    http://puccaso.com

  2. #2
    Join Date
    Jul 2007
    Beans
    43

    Re: mysql issue

    PHP Code:
    CREATE TABLE `customer` (
    `
    customer_idintNOT NULL auto_increment,
    `
    usernamevarchar(20collate ascii_bin NOT NULL default ''

    ....
    ....

    PRIMARY KEY  (`customer_id`),
      
    UNIQUE KEY `username_unique` (`username`)

    Where you would declare your key constraints at the end mark the column as unique.

  3. #3
    Join Date
    Apr 2005
    Location
    Turkey
    Beans
    353
    Distro
    Ubuntu Development Release

    Re: mysql issue

    as the mounty in due south says

    thank you kindly
    ____________________________
    Mahir Sayar
    http://puccaso.com

  4. #4
    Join Date
    Apr 2005
    Location
    Turkey
    Beans
    353
    Distro
    Ubuntu Development Release

    Re: mysql issue

    mmm
    one question

    why username_unique tho?
    ____________________________
    Mahir Sayar
    http://puccaso.com

  5. #5
    Join Date
    Nov 2007
    Beans
    5

    Re: mysql issue

    'username_unique' is incorrect. Use this instead: UNIQUE KEY `username` (`username`)...

  6. #6
    Join Date
    May 2007
    Location
    Paris, France
    Beans
    927
    Distro
    Kubuntu 7.04 Feisty Fawn

    Re: mysql issue

    Quote Originally Posted by puccaso View Post
    why username_unique tho?
    Every index has to be given a name. In this case, bobrocks chose to call the index "username_unique" but it could have been anything.

    Quote Originally Posted by Jawahir View Post
    'username_unique' is incorrect.
    Not even close to incorrect, it is perfectly valid. Try it and you'll see (as I said above, it's only the index name so it hardly matters but for ALTER TABLE statements that modify/delete that index).
    Not even tinfoil can save us now...

  7. #7
    Join Date
    Jul 2007
    Beans
    43

    Re: mysql issue

    What aks44 said.

    I just chose the name as it was a unique key on a username column. No other reason, you can call it what ever you wish.

Bookmarks

Posting Permissions

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