Access the basic principles and norms developed in the construction of the table (under)

Then Previous
1, generally each table should create a primary key, the primary key is the main index, most of the primary key are built on a field, but it does not mean that it can only be a primary key field, it can also create on multiple fields. For example, orders us into the "Order Form" and "Order List" two tables in the "Order Form", we use the "Order Number" as the primary key, and in the "Order List", we can use the "Order Number" and "number" fields do two primary key.
According to Microsoft's official advice is to make use of automatic number field as the primary key field (Automatic Number usefulness of this type of data it is mainly used here), but not all the time be applicable, or prepared according to the actual situation. Typically using automatic number as a primary key, which is used primarily to establish a relationship table and the other, generally as shown in the entry need not form. The benefits of using automatic numbering of its data is automatically maintained by the database engine, and can not be modified, as long as we can make use of them without having to care about the add, modify how data is time to deal with it. It will only inconvenience is automatically incremented after using the maximum number, if we remove some of the numbers that will not be filled renewal.
2, often used for field queries we can build on its index. The principle of indexing is to try only indexed data is small and there is no record basically empty field. But the index can not build too much, otherwise not only can not speed up the search, but will result in system complexity of index maintenance, but reduces performance. Index are generally built on relatively small data field types, such as date, numeric field; if it is a text field type, field size should not be too large, the general field size should not exceed 50, otherwise you will need to consider indexing of the; and Memo, OLE Object fields are not allowed to fully indexed.
3, just to start, we can analyze the need for reverse thrust by the report which tables used in practice, as well as table roughly what fields. Table general there are two main categories, is stored, such as product, employee, customer information base table, the data in other tables are a combination of these basic data from. Products, employees, customers three appearances for the Orders table, the Orders table belongs to the business table of the second layer, when we fill out the form to this type of data, most of the data to be taken from the front of the base table . Of course the practical application of the complexity of the business process, there may be a third layer, the fourth layer, layer N, this is just a generalization of classification.
4, the existing fields in the table on the basis of the relationship between fields in addition, should not be repeated in the other tables. For example, the product table stores all product information, so in addition to the Order Details table in the product table's primary key field there should be no other existing products in the fields in the table. If you need to show the information in the order details, we can create a query by relationships in the application, to obtain the corresponding data from the Products table in a query.
5, related tables should build relationships and referential integrity, so as to ensure the validity of data. The main role of the relationship is to eliminate data redundancy, and facilitate the establishment of inquiries. Many beginners do not understand the relationship or do not pay attention, they did not focus, resulting in a design queries too messy, inefficient, and establish a database of invalid and useless data is prone to. For example, between Orders and Order Details tables, if not established relationships and referential integrity, when data is deleted from the Orders table, Order Details table related records still exist, which obviously resulted in useless data. If we modify the customer table in the customer's name, but did not use referential integrity relationship to ensure data integrity, and thus may cause this customer-related data on orders from a normal query can not find here.
For the use of renewable field as the primary key, you should also select the Cascade updated when building relationships. Cascading Updates role is, if the order of the table is to build relationships through customer name and customer list, when we changed the name of the customer in the customer table, the Orders table of customer name will be changed automatically. As cascade delete feature, which according to circumstances, such as when the Orders table and the Order Details table you can select the cascading deletes, so we remove the orders table order history, order schedule and other related records on the Order Details It will be automatically deleted. But for customers like customer table and the category table like this, do not set up cascading deletes, or if you delete a customer categories, all the categories of customer data will be deleted, no place to cry cry. So try not to use the cascade delete feature for when more important data, you sure you want to delete, then, can be done to delete the records related to the child table, and then delete records in the primary table manner.
Why has repeatedly stressed the validity of data? In fact, the answer to this question is obvious. From which to analyze the information we want, the role of the database is through strict segmentation and validation of data to ensure accurate data and detailed data effectively and accurately use only, from which we can analyze more wanted information. For example, we want to count against a customer sales orders, the orders between the Customer table and the table is linked to the customer by name. Thus if we are in the Orders table in a bar or a few records in the customer name mistyped or has been modified, but we did not pass the validity of the data to maintain referential integrity, customer name in the table and we entered when the query statistics as customer names do not match, the final out of the sales statistics naturally, is simply not correct, we can not get the correct information. Situation like this, we not only will not use the database to enhance work efficiency and facilitate management, but our work will be misleading, and therefore may even result in losses.
6, for the validation of the data to the database engine should try to deal with. That is to build the table when they should try to design a good, rather than to deal with through the code in a form, which is not easy to guarantee the effectiveness of.
The database verification to the database engine to deal with, we will save a lot of repetitive work, only need to capture the appropriate error and the user is prompted to, and make the appropriate treatment on the line. If all else on the form to verify the validity of each item in code words, a person's job will be exhausted. Validation in the table at this level is the most effective and most reliable way, no comprehensive data is not considered reason or unpredictable when writing code that caused abnormal update, insert, delete, and so on.
In the field validation rules we can use all of the logical operator conditions can be used in Access as =,>,> =, < , <=, Like, In, Between ... And the like. In addition to the kind of cross-validation field (such as the delivery date can not be earlier than the date of the next single) outside, we can almost all be based on a single field validation.
7, the field should be used whenever a minimum, the most appropriate data type and field size. The product of the number of the field should be used or long integer data types, rather than single and double-precision data type; and the like of the employee name in the employee table is generally not exceed (in some countries course 10 characters the kind of people or ethnic names read it several times to break the air is not too _ we here say is China's name), so we do not need to field size is set to 50 or 255, to do so would be a waste storage space and degrade performance. And when we want to sort the data for statistical calculation processing, it must use the correct data type for the job, each data type comparison calculation is not the same, for example, if it is digital, we want to sort of draw the results must be in descending order, from small to or arranged to, if the data type field is set into text-based, it will follow the ordering of the text, as will be later 1 2 10 instead of .
(Note: the smaller the data is not necessarily higher efficiency type, there are exceptions, the most efficient operation in Access data types are integer, long integer, currency, due to the use of these types of frequency in the application highest, computer systems have done their optimization, but it is smaller than the computational efficiency of the data byte)
8, the table should only be used to store data, and should not be used to enter or edit data. Unless it is otherwise, all the data editing work should be carried out in the form at the development stage. After the development is completed, not only is the table, the other Access database objects should not be exposed directly to the end user display, all operations should be completed by interactive form.

Published 10 original articles · won praise 8 · views 3832

Guess you like

Origin blog.csdn.net/weiisiceman/article/details/89318789