Can anybody tell me the difference between a Primary key and
a Unique Key ?Kindly let me know the idea.Any help would be
highly appreciated.

Dani AI

Generated

A short, practical clarification that builds on and : a primary key is the table's chosen candidate key used as the main row identifier; a unique constraint defines an alternate candidate key. Both are enforced by the engine and are usually implemented with a unique index, but behaviour (index type, clustering, NULL handling) depends on the RDBMS. Unique constraints can let NULLs in most engines; a primary key cannot. Multiple unique keys are allowed; only one primary key per table.

Steps for creating a Unique Key in MS Access (single-field and composite):

  • Open the table in Design View.
  • For a single-field unique constraint: set the field property Indexed = Yes (No Duplicates).
  • For a composite unique constraint: open the Indexes dialog (Design View -> Indexes), create an index name, add the fields in the order required and set that index to be unique.
  • To make the main key, use the Primary Key button (this marks the field(s) as the table PK).

Practical notes and tips:

  • Name constraints/indexes so ALTER/DROP is easy later.
  • Prefer a simple surrogate PK (Autonumber) and use unique constraints for business keys/alternate IDs.
  • Watch NULLs, zero-length strings and case/whitespace when duplicates appear in Access.
  • Remember DBMS specifics: e.g., SQL Server often creates a clustered index for a PK by default; Oracle creates a unique index for it. Foreign keys can reference either a primary or a unique key in common RDBMS implementations.

Recommended Answers

All 4 Replies

Unique key enforces only uniqueness (no duplicate) where as a Primary key enforces both uniqueness and not null (data must be entered into the field). Once a PK is created on a column oracle creates an index on the column.

commented: good +22

generally if i want primary key in ms access table.i just w.c on the
filed .and access create primary key.But how should i make Unique
Key in Ms Access table .Kindly let me know the idea.any help would
be highly appreciated.

You need to change the field properties.

Bothe Primary key and unique constraints are using to uniquly identify the each record in the database.
The main Differnce are,.

1)There is only one primary key in one table but we can have multiple unique key in one table
2)We can have null value in Unique key column but we cannot have null value in primary key column.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.