1-866-245-5224 sales@keystonelearning.com

Access 2007: Setting Primary Keys

Access 2007: Setting Primary Keys

You already know from our topic on database design that the primary and foreign keys determine how the tables in your database relate to each other. Further, a primary key is a field (or combination of fields) that contains a value that uniquely identifies a record.

Primary key fields:

     
  • Have values that are never blank
     
  •  
  • Include as few fields as necessary
     
  •  
  • Never allow duplicates
     
  •  
  • Can be any datatype
     

Each table should always have a primary key. In fact, Access automatically creates an index for the primary key, which helps speed up queries and other operations. Access also ensures that every record has a value in the primary key field, and that it is always unique.

When you create a new table in Datasheet view, Access automatically creates a primary key for you and assigns it a field name of “ID” and the AutoNumber data type. The field is hidden in Datasheet view, but you can see it if you switch to Design view.

Setting the Primary Key

     
  1. View your table in Design View

  2. Select the field (or fields) that you want to use as the primary key

  3. Choose the Primary Key command in the Tools group on the Design tab

Removing the Primary Key

     
  1. View your table in Design View
     
  2.  
  3. Select the field (or fields) that contain the primary key you want to remove
     
  4.  
  5. Choose the Primary Key command in the Tools group on the Design tab