In Access, use a unique index to block duplicate values in one or more fields; use a primary key when that field is the table’s main identifier. If you skip it, duplicate rows can break forms, queries, lookups, and imports. This guide shows how to find and delete existing duplicates, set the right uniqueness rule, and keep new imports from creating them again.
Unique index basics
A unique index tells Access to reject duplicate values in the indexed field or field combination. It can be single-column or multicolumn, and Microsoft says it also gives the query optimizer more information. That helps with data integrity and search speed.
Single-field versus multicolumn uniqueness
A single-field unique index fits values that must never repeat on their own, such as an employee number or part code. A multicolumn unique index fits a business key made from several fields, such as LastName + FirstName + MiddleName, where the combination must be unique even if each field alone is not.
A normal index may allow duplicates, while a unique index is generally used to prevent them. That difference matters when a form, import, or query must stop the same record from being entered twice.
How uniqueness differs from a normal index
A regular secondary index mainly helps lookups, joins, and sorting. A unique index also enforces a rule. Microsoft notes that unique indexes can improve optimizer information, but FMS also warns that too many indexes can hurt performance and increase database size.
That is why you should index with intent. Add what helps searches and integrity, and avoid filling a table with secondary indexes that do little for low-value fields.
Unique index or primary key?
Use a primary key when the field is the table’s main identifier and data integrity is the main objective. Use a separate unique index when you need another field, or field combination, to stay unique without making it it the table’s primary identifier. Microsoft says a UNIQUE or PRIMARY KEY constraint automatically creates a unique index, and it recommends those constraints when integrity is the goal. (Microsoft)
When a primary key is the better choice
A primary key is the better choice for the table’s core row identity, such as a record ID that every related table points to. Access automatically creates a unique index when you define the primary key, so you get uniqueness enforcement without adding a second rule on the same field.
When a separate unique index makes more sense
Use a separate unique index when the table already has a primary key but another field still needs to stay unique. A customer table may need a surrogate primary key plus a unique email field, or a product table may need a unique SKU while the row ID stays hidden.
Where UNIQUE constraints fit in Access
Microsoft groups UNIQUE and PRIMARY KEY constraints with the same goal: enforce uniqueness and automatically create a unique index. In Access design work, that means you should choose the object that matches the job. If the point is identity, make it a primary key. If the point is a business rule, a unique index or UNIQUE constraint can fit better.
Find duplicates before you change
You cannot create a unique index or UNIQUE constraint if duplicate key values already exist. Microsoft says duplicate values block index creation, so the table needs cleanup first. Find the repeats, decide which row to keep, and remove or correct the rest before you lock in the rule.
How to find existing duplicates
- List the suspected fields. Start with the field or combination that should be unique, such as Email, SKU, or LastName + FirstName + MiddleName. If the rule spans more than one field, search on the combination, not on each field alone.
- Build a duplicate query. Use an aggregate query that groups by the target fields and counts matching rows. Any group with a count greater than 1 is a duplicate set. That gives you a short list before you touch table design.
- Open the duplicate rows. Review the repeated records one set at a time. Decide whether one row should remain, whether values need correction, or whether the duplicates came from a bad import and should be replaced.
- Remove or correct records. Delete only the extra rows or edit the values so each key becomes unique. Run the duplicate query again until no repeated key values remain. That keeps the new index from failing later.
Suppose a table stores customer names and a business rule says the combination of LastName, FirstName, and MiddleName must be unique. Two rows may both contain “Nguyen, Minh, T.” in separate records after an import. A multicolumn unique index will not be created until one of those rows is fixed or removed.
How do you create the unique rule in Access?
In Access, add the rule in table design after the data is clean. If the field is already unique, set it as a primary key or unique index as appropriate. If it already contains duplicates, fix those rows first, because Access will not create the rule while repeated key values still exist.
Table Design view approach
- Open the table in Design view. Select the field or fields that should be unique. For a multicolumn rule, define the index across the field combination rather than on each field individually.
- Set the uniqueness rule. Mark the field as a primary key if it is the main identifier, or create a unique index if it is a separate business rule. Use a UNIQUE constraint when your design standard is based on constraints and integrity rules.
- Save the table structure. If duplicates remain, Access will reject the change. Clean the data first, then save again so the uniqueness rule can be stored.
Using an existing business key
A business key is often the best place for a multicolumn unique index. A common first-timer mistake is indexing only one field, such as FirstName, when the real rule is the combination of name parts. That allows duplicate people with the same first name and defeats the purpose.
If the business key has blank or Null values, check those records before you lock in the rule. Uniqueness rules should match the way the data is actually entered, not the way the table is hoped to behave later.
Unique index decision checklist
Use this checklist before you pick the object. The right choice depends on whether the field is the table’s main identifier, a business rule, or an imported field that keeps getting rebuilt. It also depends on whether the data is already clean enough for the rule to stick.
| Scenario | Best Access object | Pre-check needed | Failure risk |
|---|---|---|---|
| New table with one main identifier | Primary key | Confirm the identifier is never blank or repeated | Low if the identifier is stable |
| Legacy table with duplicates already present | Unique index after cleanup | Find and remove duplicate key values first | High until the duplicates are removed |
| Composite business key such as LastName + FirstName + MiddleName | Unique index or UNIQUE constraint | Check the full field combination, plus Null and blank handling | Medium if any component is inconsistent |
| Imported table with AutoIndex turned on | Primary key or unique index after import review | Review automatically added secondary indexes before loading more data | Medium to high if duplicate indexes or bad keys are carried forward |
How do you stop duplicate entries from coming back?
Stop the problem at the import and form layer, not only at the table layer. Access can automatically add secondary indexes during import or create actions, and Microsoft notes that AutoIndex names can, depending on version and settings, watch for fields beginning or ending with ID, key, code, or num. If you want full control, set automatic indexing to nothing.
Import settings and AutoIndex behavior
- Review field names before import. Check names that match the AutoIndex patterns, because Access can add secondary indexes automatically on import or create. That includes names beginning or ending with ID, key, code, or num, depending on version and settings.
- Turn off automatic indexing. Set AutoIndex to nothing when you want full control over indexing. In Access, open File > Options and check the database’s import/create indexing setting in the Options dialog before loading repeated files.
- Remove unneeded secondary indexes. Keep the indexes that support searches and links between tables, and drop the ones that do not add value. Some fields with only a few unique values do not benefit much from secondary indexes, and extra indexes can hurt performance and increase database size.
Form-level checks versus table-level enforcement
Table design should be the final backstop. Forms can warn users early, but a table-level unique index is what actually helps block invalid or duplicate data from being stored. That matters when non-technical users type into a form and expect Access to catch duplicates before save.
When a user enters a duplicate value, Access rejects the record update or insert and shows a duplicate-key failure. The exact text can vary by version and context, so treat it as a duplicate-entry error rather than relying on a single wording. The important part is that the save does not succeed.
What should you check before you lock the rule in?
Check Nulls, blanks, imported rows, and index count before you finish. A uniqueness rule can fail or mislead if a field allows inconsistent blanks, if an import brings back duplicates, or if too many secondary indexes are slowing the table. Microsoft also notes that unique indexes can give the optimizer more information, but that benefit does not excuse unnecessary indexing.
Null and blank values
Review how the table handles empty entries before you rely on uniqueness. A field that allows blank text, Nulls, or placeholder values can still produce confusing results if those values are treated inconsistently across forms and imports. Clean rules work best when the data-entry pattern is clear.
Duplicate cleanup after imports
Imported tables can bring in a whole set of new secondary indexes automatically. That is useful only when the indexes match the real design. After an import, review the table, confirm which indexes are needed, and remove the rest so the table does not keep rebuilding the same problem.
Performance and file-size tradeoffs
Too many indexes are a cost. FMS says extra indexes can hurt performance and increase database size, so do not index every field that looks important. Favor fields used in searches, joins, and integrity rules, and leave low-value fields alone unless they genuinely need the index.
Picture a table imported from a spreadsheet where fields named ProductCode and OrderNum were both auto-indexed, plus a manual unique index was added later. If the table is rarely searched by OrderNum, that index may add maintenance cost without enough payoff. Keep the rule, remove the excess.
Which fields should not be indexed in Microsoft Access?
Do not index every field by default. Fields with very few unique values, fields that are rarely searched, and fields that are updated constantly usually do not repay the extra overhead. Secondary indexes help searches and links, but they also add maintenance work and file size.
A field should be indexed only when the query pattern, join pattern, or uniqueness rule needs it. That keeps the table easier to maintain and reduces the chance that imported data creates duplicate or unnecessary indexes.
Frequently asked questions
How do I prevent duplicate entries in Microsoft Access with a unique index?
Create the unique index on the field or field combination that must not repeat, then make sure existing duplicates are gone first. Access will block any later insert or update that tries to reuse the same indexed value. Use a form for early feedback, but keep the table rule as the final enforcement.
What is the difference between a unique index and a primary key in Access?
A primary key is the table’s main identifier, and Access creates a unique index automatically when you define it. A unique index also enforces uniqueness, but it can be used on another field or field combination that should stay unique without becoming the table’s primary identifier. Choose by role, not by habit.
How do I find existing duplicates before creating a unique index?
Use a query that groups by the target field or field combination and counts matching rows. Any group with more than one record is a duplicate set. Review those rows, decide which one stays, and remove or correct the others before you add the unique rule.
Can a unique index be created if duplicate values already exist?
No. Microsoft says duplicate key values prevent creating a unique index or UNIQUE constraint. Access will reject the change until the duplicate values are removed or corrected. Clean the table first, then create the rule after the data is unique.
Should I use a unique index or a UNIQUE constraint in Access?
Use either when the objective is integrity and uniqueness. Microsoft says a UNIQUE or PRIMARY KEY constraint automatically creates a unique index, and it recommends those constraints when data integrity is the goal. In practice, choose the one that matches your design standard and table role.
How do I stop Access from creating duplicate indexes on imported tables?
Review AutoIndex behavior before import or create actions. Access can automatically add secondary indexes for field names that begin or end with ID, key, code, or num, and those names are configured in the Options dialog. Set automatic indexing to nothing when you want full control.
What happens when a user tries to enter a duplicate value?
Access rejects the insert or update that violates the unique rule. The user sees a duplicate-entry failure, and the record does not save. That is why table-level enforcement matters even when a form already checks for duplicates.