Chinese Access2000 Express Tutorial--1.6 define "PRIMARY key" _access

Source: Internet
Author: User

The definition of "primary key" in Chinese Access 2000, a large data base can be built, and to use the data distributed in different tables as a "library", it is necessary to establish a "primary key" for each table to establish a relational database system. This system is characterized by the ability to quickly find data using queries, forms, and reports, and to combine information from different tables. If you want to do this, each table should contain the same one or a set of fields, it is all stored in the table, the unique identification of each record, that is, the table's "primary key", usually need to set up when the data table, in order to save time, so this chapter here inserted this section.


Chinese Access 2000 allows you to define three types of primary keys: AutoNumber, field, and multiple fields, and their characteristics are described below.

1. Automatic numbering primary key 


In the previous operation, you must have noticed that when you add a row of records to a table, Chinese Access 2000 always automatically sets the number, even if you specify a different number, the software allows you to set the AutoNumber field to automatically enter the number of consecutive numbers, thereby assigning the AutoNumber field as the primary key of the table. This is the easiest way to create a primary key, and I'm sure you'll remember that before that.


In fact, if you do not set a primary key before you save the new table, Chinese Access 2000 asks if you want to create a primary key. If you answer yes, you will create an AutoNumber primary key. This method of establishing a primary key can be applied to any table in Chinese Access 2000, which is not so convenient in Chinese visual FoxPro 6, which is difficult for beginners to master.

Note: After you specify a primary key for a table, Chinese Access 2000 prevents you from entering duplicate values or Null in the primary key field to ensure its uniqueness. Null indicates that there is no value in the field, or an unknown value.

2. Single Field primary key


If you have the same field in some information-related tables, and you include a unique value, such as an ID number or part number, you can designate the field as the primary key. If you select a field that has duplicate values or Null values, Access 2000 will not set its primary key, so you can run the Find Duplicates query to find the record that contains the duplicate data, and then edit to modify it.


Note: If you are still not easily able to eliminate these duplicates by editing the data, you can add an AutoNumber field and set it as the primary key, or define a multiple-field key, which is a useful technique.

3. Multi-field Primary key


When you cannot guarantee that any single field contains unique values, you can designate two or more fields as primary keys. This situation most often occurs in tables that are used to associate two other tables in a many-to-many relationship. "Many-to-many Relationships" is a more difficult concept in relational databases, but it is very practical, stating that records in Table A can match many row records in table B, and records in table B can match many rows in table A. The type of this relationship can only be implemented by defining a third table, called a "join table", whose primary key contains two fields, that is, the foreign key from both tables A and B. A many-to-many relationship is actually a two one-to-many relationship using the third table. For example, the Orders table and the Products table might have a many-to-many relationship created by two one-to-many relationships in the Order Details table.

Note: "One-to-many relationship" is the most common type of relationship. In this relationship, a row in table A can match a number of row records in table B, but a row in table B can only match a row of records in Table A. If a row in table A records matches only another row in table B, this is a one-to-one relationship. Therefore, "one-to-one relationship" can be considered as a special case of "one-to-many relationship". Multi-relationship, one-to-one relationship and one-to-many relationship are the basic concepts of applying relational database.

To specify or change a primary key, you can open the table in Design view, and then select the field or fields from the row selector that you want to define as the primary key, and then click the Primary Key button on the Design view toolbar to see figure 29. To delete a primary key, just select it in the row selector, and then click the Primary Key button on the Design view toolbar, as shown in Figure 32.





Figure 29 Click this button

If you don't see the Design view toolbar on the screen, you can't use the primary key button. To make it appear, you need to click the View Drop-down button on the Database View toolbar, and then select Design View from the Drop-down menu, and it will appear, as shown in figures 32 and 9-33.





Figure 30 Click this Drop-down button





Figure 31 Select this command






Figure 32 The location of the line selector
Note: When you select a field, you only need to click the appropriate box in the row selector. To select more than one field, press the CTRL key and click their boxes in the row selector, see figure 34

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.