Question:
Please Help on MS Access?
Jethro P
2008-10-28 23:14:30 UTC
Can a single table in MS Access have two primary keys? If so how do you define them so I can link three tables into one?
Five answers:
Soie R
2008-10-28 23:19:23 UTC
I initially said No also - meaning that you have to create separate tables and have a primary key in each table, but then I found this in the Access help section, so I hope it helps answer your question.



In situations where you can't guarantee the uniqueness of any single field, you may be able to designate two or more fields as the primary key. The most common situation where this arises is in the table used to relate two other tables in a many-to-many relationship (many-to-many relationship: An association between two tables in which one record in either table can relate to many records in the other table. To establish one, create a third table and add the primary key fields from the other two tables to this table.). For example, an Order Details table can relate the Orders and Products tables. Its primary key consists of two fields: OrderID and ProductID. The Order Details table can list many products and many orders, but each product can only be listed once per order, so combining the OrderID and ProductID fields produces an appropriate primary key.



Each product can be listed only once per order.



Another example would be an inventory database that uses a field part number of two or more fields (part and subpart).



If you are in doubt about whether you can select an appropriate combination of fields for a multiple-field primary key, you should probably add 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 and designate it as the primary key instead. For example, combining FirstName and LastName fields to produce a primary key is not a good choice, since you may eventually encounter duplication in the combination of these two fields.



In a multiple-field primary key, field order may be important to you. The fields in a multiple-field primary key are sorted according to their order in table Design view (Design view: A window that shows the design of these database objects: tables, queries, forms, reports, macros, and data access pages. In Design view, you can create new database objects and modify the design of existing ones.). You can change the order of the primary key fields in the Indexes window (Indexes window: In an Access database, a window in which you can view or edit a table's indexes or create multiple-field indexes.).
anonymous
2014-05-05 05:29:16 UTC
One table has only one primary key. Do you know composite key ? Composite key means we can apply primary key based on 2 or more fields within one table. But duplicating on one column. It restrict to entry data looking multiple column unique data. Thank you
Charles R
2008-10-28 23:38:06 UTC
As the previous answer said you can use to fields as a primary key it is called a composite key. What he forgot was to tell you how. Display your table design view. Select the first part (field) of your key hold the ctrl key down and select the second part of your key. Be sure you select the entire rows. Once you have done that right click on one of the selected fields select primary key from the context menu and you are done.
anonymous
2008-10-28 23:22:39 UTC
Noo, You can only have one Primary Key, this stops duplicates of records. You link them by having a primary key for each table
qu4tr0
2008-10-29 00:01:36 UTC
i dont think you can choose 2 fields for a primary key, thats why its called PRIMARY. you can try to sort fields by using the INDEXED property on Design view of a table. you can choose "Yes (with duplicates)" or "Yes (without duplicates)".



to link 3 tables into 1, try joining them. check this: http://office.microsoft.com/en-us/access/HP051885681033.aspx


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...