if you're talking about databases
About primary keys (MDB)
Show All
Hide All
The power of a relational database system such as Microsoft Access comes from its ability to quickly find and bring together information stored in separate tables using queries (query: A question about the data stored in your tables, or a request to perform an action on the data. A query can bring together data from multiple tables to serve as the source of data for a form, report, or data access page.), forms (form: An Access database object on which you place controls for taking actions or for entering, displaying, and editing data in fields.), and reports (report: An Access database object that prints information that is formatted and organized according to your specifications. Examples of reports are sales summaries, phone lists, and mailing labels.). In order to do this, each table should include a field or set of fields that uniquely identifies each record stored in the table. This information is called the primary key of the table. Once you designate a primary key for a table, Access will prevent any duplicate or Null (Null: A value you can enter in a field or use in expressions or queries to indicate missing or unknown data. In Visual Basic, the Null keyword indicates a Null value. Some fields, such as primary key fields, can't contain Null.) values from being entered in the primary key fields.
There are three kinds of primary keys that can be defined in Microsoft Access:
AutoNumber primary keys
An AutoNumber (AutoNumber data type: In a Microsoft Access database, a field data type that automatically stores a unique number for each record as it's added to a table. Three kinds of numbers can be generated: sequential, random, and Replication ID.) field can be set to automatically enter a sequential number as each record is added to the table. Designating such a field as the primary key for a table is the simplest way to create a primary key. If you don't set a primary key before saving a newly created table, Microsoft Access will ask if you want it to create a primary key for you. If you answer Yes, Microsoft Access will create an AutoNumber primary key.
AutoNumber primary keys in a replicated database
There are additional considerations if your table will be used with database replication (database replication: The process of creating two or more special copies (replicas) of an Access database. Replicas can be synchronized, changes made to data in one replica, or design changes made in the Design Master, are sent to other replicas.).
If fewer than 100 records are routinely added between synchronizing replicas (replica: A copy of a database that is a member of a replica set and can be synchronized with other replicas in the set. Changes to the data in a replicated table in one replica are sent and applied to the other replicas.), use a Long Integer setting for the FieldSize property to take up less disk space.
If more than 100 records are routinely added between synchronizing replicas, you should use Replication ID for the FieldSize property setting to prevent records from being assigned the same primary key value in each replica. Note, however, that an AutoNumber field with a Replication ID field size produces a 128-bit value that will require more disk space.
Single-field primary keys
If you have a field that contains unique values such as ID numbers or part numbers, you can designate that field as the primary key. You can specify a primary key for a field that already contains data as long as that field does not contain duplicate values or Null values.
Multiple-field primary keys