Prevent duplicate values in a field

You can prevent duplicate values in a field by creating a unique index. A unique index is an index that requires that each value of the indexed field is unique.

There are two basic ways that you can create a unique index:

  • Set the field's Indexed property to Yes (No duplicates)    You can do this by opening the table in Design view. This method is easy and a good choice if you only want to change one field at a time.

  • Create a data-definition query that creates the unique index    You can do this by using SQL view. This method is not as easy as using Design view, but has an advantage: you can save the data-definition query and use it again later. This is useful if you periodically delete and re-create tables and want to use unique indexes on some of the fields.

What do you want to do?

Set a field's Indexed property to Yes (No duplicates)

Create a unique index for a field by using a data-definition query

Set a field's Indexed property to Yes (No duplicates)

  1. In the Navigation Pane, right-click the table that contains the field, and then click Design View.

  2. Select the field that you want to make sure has unique values.

  3. In the Field Properties pane, on the General tab, set the Indexed property to Yes (No duplicates).

    The Indexed Field Property

Top of Page

Create a unique index for a field by using a data-definition query

  1. On the Create tab, in the Other group, click Query Design.

  2. On the Design tab, in the Results group, click the arrow under View, and then click SQL View.

  3. Delete all the SQL from the query.

  4. Type or paste the following SQL into the query:

    CREATE UNIQUE INDEX index_name
    ON table (field)
  5. In the SQL, replace the variables as follows:

    • Replace index_name with a name for your index. It is a good idea to use a name that helps you determine what the index is for. For example, if the index is to make sure that social security numbers are unique, you might name it unique_SSN.

    • Replace table with the name of the table that contains the field to be indexed. If the table name has spaces or special characters, you must enclose the name in square brackets.

    • Replace field with the name of the field to be indexed. If the field name has spaces or special characters, you must enclose the name in square brackets.

  6. Save and close the query.

  7. Run the query to create the index. Note that you can run the query from a macro by using the RunSQL macro action. For more information, see the See Also section.

Top of Page

Applies To: Access 2007



Was this information helpful?

Yes No

How can we improve it?

255 characters remaining

To protect your privacy, please do not include contact information in your feedback. Review our privacy policy.

Thank you for your feedback!

Support resources

Change language