Click to See Complete Forum and Search --> : Cold Fusion / SQL how do I make sure "username" is unique?
sparq
03-07-2005, 09:26 AM
To avoid alot of potential problems, I want to make sure a user inputted "username" field is unique from all other entries in a table. How can I do this when creating it? I already have a unique ID for each row, but I want to make sure that multiple people aren't sharing the same username. Any help would be appreciated!
buntine
03-07-2005, 07:26 PM
You can perform an SQL SELECT statement before entering the new record. It would be created similar to this in most programming environments:
SELECT user_name FROM users WHERE user_name = '" + userNameVariable + "';"
Obviously, you will have to alter the table/column names to conform to your data model.
If this query returns a record, then the user is creating a duplicate name and you should return with an error.
Regards.