Reputation: 51
I read in this site that it is recommended use an auto-number ID rather than username for primary keys because it will not change. However, how do I prevent the database to have only unique usernames. I am using Access.
Upvotes: 1
Views: 1692
Reputation: 837
I take it you've already made the table, so run this query:
ALTER TABLE users
ADD UNIQUE(username)
Change table name and column name in the query to match your table and column name, obviously.
Here's the reference: http://www.w3schools.com/sql/sql_unique.asp
Upvotes: 0
Reputation: 123809
In Access, open the table in Design View and click on the username
field. In the "Field Properties" pane at the bottom, select Yes (No Duplicates)
for the Indexed
property. That will prevent duplicate username
values from being entered.
Upvotes: 5
Reputation: 917
Set unique constraint on username column (some main table for user). You always can validate before inserting (for prompting user) or on trigger before insert.
Upvotes: 1