Jake Mogra
Jake Mogra

Reputation: 51

Prevent non-primary key column to have duplicates

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

Answers (3)

vanamerongen
vanamerongen

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

Gord Thompson
Gord Thompson

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

BlueConga
BlueConga

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

Related Questions