Oh great Stackoverflow, I beseech thee…
I need to do the following:
CREATE UNIQUE INDEX UserName ON Emp(UserName) — Sheesh!
UPDATE Emp SET
UserName = Left(FirstName,1)+LastName
WHERE NOT exists an employee with that UserName already.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This will still allow duplicates… but if you want what you said,
Try this (exactly what you said):
I’d guess, however, that you are trying to avoid duplicates, not just reset UserNames where no existing one is the same as the proposed new value. If so, you should add a unique index on the userName column, but first, run this:
This will reset all the UserNames that CAN be reset without creating duplicates. (It will not eliminate existing Dupes). If there are no dupes after this, you can apply the index.