Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
Design | data | database | Database Design relational database design is to follow certain rules. In particular, database design paradigm is briefly introduced 1NF (first normal form), 2NF (second normal form), 3NF (third normal form) and BCNF, another fourth normal form and fifth normal form are left to be introduced later. When you design a database, if you can meet these paradigms, you are the master of database design.
The first paradigm (1NF): In each specific relationship in the relational mode R, if each attribute value is a minimum data unit that is not to be divided, it is said that R is the relationship of the first normal form. Example: such as employee number, name, telephone number composed of a table (a person may have an office phone and a home phone number) specifications to become 1NF there are three ways: one is to repeatedly store the employee number and name. This way, the keyword can only be a phone number. Second, the employee number is the key word, the telephone number is divided into the unit telephone and the residential telephone two properties three is the employee number is the keyword, but forces each record to have only one telephone number. The above three methods, the first method is the most undesirable, according to the actual situation after the selection of two cases.
Second Normal form (2NF): If all the u,f attributes in the relational schema R (s) are completely dependent on any candidate keyword, then the relation R is called the second normal form. Example: Elective course relationship SCI (Sno,cno,grade,credit) in which SNO for the study number, CNO for the course number, Gradege for the results, credit for credits. By the above conditions, the keyword for the combination keyword (SNO,CNO) in the application of the above relational mode has the following problems: A. Data redundancy, assuming that the same course is selected by 40 students, the credits are repeated 40 times. B. Update the exception, if you adjust the credits of a course, the corresponding META group credit value should be updated, there may be the same course credits different. C. Insert an exception, such as the plan to open a new course, because no one elective, no number of key words, can only wait for someone to take courses and credits deposit. D. Delete the exception, if the student has graduated, delete elective records from the current database. The curriculum and credit records cannot be saved if some of the new courses are not yet elective. Reason: non-keyword attribute credit only the function relies on CNO, which is the credit partial dependency combination keyword (sno,cno) rather than full dependency. Workaround: Divide into two relational patterns SC1 (Sno,cno,grade), C2 (Cno,credit). The new relationship includes two relational patterns, which are connected by the external key word CNO in the SC1, and then natural joins are needed to restore the original relationship.
Third paradigm (3NF): If all the u,f attributes in the relational schema R (s) do not exist for any candidate keywords to pass trust, then the relation R is called the third normal form. For example: the S1 (sno,sname,dno,dname,location) Each attribute represents the school number, the name, the department, the department name, the department address respectively. The keyword SNO determines each property. Because it is a single keyword, there is no partial reliance on the problem, it must be 2NF. But there must be a lot of redundancy in this relationship, and the students ' several attributes dno,dname,location will be stored repeatedly, inserted, deleted and modified will also produce similar cases. Cause: There is a transitive dependency in the relationship. namely Sno-> DNO. But the DNO-> SNO does not exist, DNO-> LOCATION, so the key Liao SNO the LOCATION function decision is realized by the transmission dependence SNO->. In other words, Sno does not directly determine the non-primary attribute location. Solution: No transitive dependencies can be left in each relational pattern. Workaround: Divided into two relationships S (sno,sname,dno), D (dno,dname,location) Note: The relationship S can not have no external keyword DNO. Otherwise two relationships lose touch.
BCNF: If all of the properties of the relational schema R (U,F), including both primary and non-primary properties, do not pass any candidate keywords that depend on R, then the relationship R is called BCNF. or relational schema R, if each determinant contains keywords (rather than being included by the keyword), then the RCNF relational schema. Example: Accessory Management Relationship Mode WPE (WNO,PNO,ENO,QNT) Separately table warehouse number, accessory number, employee number, quantity. There are the following conditions a. A warehouse has multiple employees. B. A worker works only in one warehouse. C. One type of accessory in each warehouse is manned by a person, but one can manage several accessories. D. Accessories of the same type can be divided into several warehouses. Analysis: By the above PNO can not be determined qnt, by the combination of attributes (Wno,pno) to determine the existence of functional dependencies (Wno,pno)->eno. Because one of the accessories in each warehouse is responsible for a person, and one can manage several accessories, so there is a combination of attributes (Wno,pno) to determine the person in charge, there is (wno,pno)-> ENO. Because a worker works only in a warehouse, there are ENO->wno. Since one of the accessories in each warehouse is in the hands of a person, and a worker works only in one warehouse, there are (Eno,pno)-> QNT. Find the Candidate keyword because (wno,pno)-> QNT, (wno,pno)-> ENO, so (wno,pno) can determine the entire tuple, which is a candidate keyword. According to Eno->wno, (eno,pno)->qnt, therefore (Eno,pno) can also determine the entire tuple for another candidate keyword. Property eno,wno,pno are all primary properties and only one qnt property is not. It is fully functional dependent on any candidate keyword and is directly dependent, so the relational pattern is 3NF. Analyze the main properties. Because of Eno->wno, the primary attribute Eno is a wno determinant, but it is not a keyword in itself, it is just part of a combination of keywords. This results in a partial dependency of the main attribute wno on another candidate keyword (eno,pno), because (eno,pno)->eno but not in turn, and P->wno, so (eno,pno)-> Wno is also a transitive dependency. Although there is no non-main attribute to the candidate key Liao's transmission dependence, but there is the main attribute to the candidate keyword transmission dependence, also can bring trouble. If a new employee assigned to the warehouse work, but temporarily in the internship stage, not independently responsible for certain parts of the management tasks. cannot be inserted into the relationship because it is missing a part of the keyword pno. And if a person changed to no matter the accessories to be responsible for security, then delete the accessories at the same time the staff will be deletedExcept. Solution: Divided into Management EP (ENO,PNO,QNT), the key word is (eno,pno) work EW (ENO,WNO) Its keyword is ENO disadvantage: After decomposition function dependency is poor. In this case, because of the decomposition, the function dependency (wno,pno)-> ENO is lost, thus destroying the original semantics. Does not reflect a part of each warehouse in the hands of the person responsible. It is possible to have a component managed at the same time by two or more than two people. Therefore, the relational schema after the decomposition reduces the partial integrity constraints.
A relationship breaks down into multiple relationships to make the decomposition meaningful, and the minimum requirement is to decompose without losing the original information. This information includes not only the data itself, but also the mutual constraints between the data represented by the function dependencies. The goal of decomposition is to achieve a higher level of normalization, but the decomposition must also consider two issues: lossless connectivity and retention function dependencies. Sometimes it is not possible to achieve both lossless connectivity and functional dependencies completely. Needs to be weighed as needed.
1NF until the bcnf four paradigms have the following relationship: Bcnf contains 3NF contains 2NF contains 1NF
Summary: Objective: The purpose of normalization is to make the structure more reasonable, eliminate the storage anomaly, make the data redundancy as small as possible, easy to insert, delete and update the principle: Follow the concept single The "One Thing, one place" principle, namely a relational pattern describes a relationship between an entity or an entity. The essence of the norm is the single of the concept. Methods: The relational schema projection is decomposed into two or more relational patterns. Requirements: The set of relational patterns after decomposition should be "equivalent" to the original relational pattern, that is, the original relationship can be restored without loss of information through natural joins, and a reasonable relationship between attributes is maintained.
Note: The decomposition of a relational pattern knot can get a set of different relational schemas, i.e. the decomposition method is not unique. The minimum redundancy requirement must be realized on the premise that the decomposed database can express all the information of the original database. The basic goal is to save storage space, avoid data inconsistency, improve the operational efficiency of the relationship, and meet the application requirements. In fact, it does not necessarily require that all modes reach bcnf. Sometimes intentional retention of partial redundancy may be more convenient for data queries. Especially for those database systems with low frequency of updates and extremely high query frequency.
In the relational database, in addition to the function dependence, there are many value dependencies, the connection dependency problem, thus proposed the fourth normal form, the five paradigm and so on higher level of standardization requirements. Here, we'll talk about it later.
Dear friends, What do you think after that, in fact, any book on the basic theory of the database will say these things, considering that many netizens are the halfway monk, to do the database. Special find a book big copy, you have any questions, do not ask me, I have to find a book of relational database theory to see it, perhaps, for you greatly help. Said that is the basic theory of things, please think about it, you do database design when you have not considered the following several paradigms, there is no good in the database design, think about it, compared to the above, in the end is a violation of the first few paradigm? I have seen the database design, very few people do very well in accordance with the above several paradigms, generally speaking, the first paradigm everyone can comply with, fully comply with the second third form of people are very few, abide by the person must be the master of the design database, bcnf paradigm appears less opportunities, and will destroy integrity, You can do the design without considering it, of course, in Oracle can use triggers to solve their shortcomings. When we do design together, we also hope that we will follow these paradigms.
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to firstname.lastname@example.org. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
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:
and provide relevant evidence. A staff member will contact you within 5 working days.