0

Is there anyway to make a column in mysql UNIQUE with out removing it and adding it again ? I know how to add it but i would need to remove it first but i want to edit the current column and make it UNIQUE

I do

ALTER TABLE users
ADD UNIQUE (username)

But tells me that the column username is all ready there . When i want to edit it and not add it...

Strawberry
  • 32,714
  • 12
  • 37
  • 56
  • Im guessing using UNIQUE would stop users from registering with the same username ?? – Billy White Aug 08 '13 at 15:12
  • Yes, although you will need some scripting level handling as well, otherwise your user will just get an ugly exception or an empty page. You will have to capture this situation and tell them to pick another name. – GolezTrol Aug 08 '13 at 15:14
  • the problem im having is that some how a hacker is getting into my admin account. My admin account username is admin and he makes a account up with the username admin – Billy White Aug 08 '13 at 15:17
  • Probably because that `admin` user still exists? Or if that account is able to make changes, he might have installed a backdoor for himself. – GolezTrol Aug 08 '13 at 15:19
  • 5
    Note though, that `admin` and `admin` are not the same. And depending on your database settings, neither are `admin` and `Admin` and `adMiN`. – GolezTrol Aug 08 '13 at 15:21
  • well the db says its the same and that is why i was looking to see if this UNIQUE would fix it. My site all runs off the users usernames and he has everything i have... even tho the space is there – Billy White Aug 08 '13 at 15:23
  • 1
    Why in the world would you make your admin account username "admin"? Is your admin password "password" too? – Ken White Aug 08 '13 at 15:40

1 Answers1

0
  1. Could it be that the unique index is already there?
  2. Could it be that there already are duplicates in that column?

Check MySQL - Make a Field Unique as it might fix your problem.

Community
  • 1
  • 1
Martin Tale
  • 806
  • 1
  • 6
  • 18