词条 | First normal form | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
释义 |
First normal form is an essential property of a relation in a relational database. Database normalization is the process of representing a database in terms of relations in standard normal forms, where first normal is a minimal requirement. First normal form enforces these criteria:{{fact|date=October 2018}}
Examplesthe following scenarios first illustrate how a database design might violate first normal form, followed by examples that comply.[3][4] Designs that violate 1NFBelow is a table that stores the names and telephone numbers of customers. One requirement though is to retain {{em|multiple}} telephone numbers for some customers. The simplest way of satisfying this requirement is to allow the "Telephone Number" column in any given row to contain more than one value:
Note that the telephone number column simply contains text: numbers of different formats, and more importantly, more than one number for two of the customers. We are duplicating related information in the same column. If we would be satisfied with such arbitrary text, we would be fine. But it's not arbitrary text at all: we obviously intended this column to contain telephone number(s). Seen as telephone numbers, the text is not atomic: it can be subdivided. As well, when seen as telephone numbers, the text contains more than one number in two of our rows. This representation of telephone numbers is not in first normal form: our columns contain non-atomic values, and they contain more than one of them. An apparent solution is to introduce more columns:
Technically, this table does not violate the requirement for values to be atomic. However, informally, the two telephone number columns still form a "repeating group": they repeat what is conceptually the same attribute, namely a telephone number. An arbitrary and hence meaningless ordering has been introduced: why is 555-861-2025 put into the Telephone Number1 column rather than the Telephone Number2 column? There's no reason why customers could not have more than two telephone numbers, so how many Telephone NumberN columns should there be? It is not possible to search for a telephone number without searching an arbitrary number of columns. Adding an extra telephone number may require the table to be reorganized by the addition of a new column rather than just having a new row (tuple) added. (The null value for Telephone Number2 for customer 789 is also an issue.) Designs that comply with 1NFTo bring the model into the first normal form, we split the strings we used to hold our telephone number information into "atomic" (i.e. indivisible) entities: single phone numbers. And we ensure no row contains more than one phone number.
Note that the "ID" is no longer unique in this solution with duplicated customers. To uniquely identify a row, we need to use a combination of (ID, Telephone Number). The value of the combination is unique although each column separately contains repeated values. Being able to uniquely identify a row (tuple) is a requirement of 1NF. An alternative design uses two tables:
Columns do not contain more than one telephone number in this design. Instead, each Customer-to-Telephone Number link appears on its own row. Using Customer ID as key, a one-to-many relationship exists between the name and the number tables. A row in the "parent" table, Customer Name, can be associated with many telephone number rows in the "child" table, Customer Telephone Number, but each telephone number belongs to one, and only one customer.[5] It is worth noting that this design meets the additional requirements for second and third normal form. AtomicityEdgar F. Codd's definition of 1NF makes reference to the concept of 'atomicity'. Codd states that the "values in the domains on which each relation is defined are required to be atomic with respect to the DBMS."[6] Codd defines an atomic value as one that "cannot be decomposed into smaller pieces by the DBMS (excluding certain special functions)"[7] meaning a column should not be divided into parts with more than one kind of data in it such that what one part means to the DBMS depends on another part of the same column. Hugh Darwen and Chris Date have suggested that Codd's concept of an "atomic value" is ambiguous, and that this ambiguity has led to widespread confusion about how 1NF should be understood.[8][9] In particular, the notion of a "value that cannot be decomposed" is problematic, as it would seem to imply that few, if any, data types are atomic:
Date suggests that "the notion of atomicity has no absolute meaning":[10][11] a value may be considered atomic for some purposes, but may be considered an assemblage of more basic elements for other purposes. If this position is accepted, 1NF cannot be defined with reference to atomicity. Columns of any conceivable data type (from string types and numeric types to array types and table types) are then acceptable in a 1NF table—although perhaps not always desirable; for example, it would be more desirable to separate a Customer Name column into two separate columns as First Name, Surname. 1NF tables as representations of relationsAccording to Date's definition, a table is in first normal form if and only if it is "isomorphic to some relation", which means, specifically, that it satisfies the following five conditions:[12] {{quote|
}} Violation of any of these conditions would mean that the table is not strictly relational, and therefore that it is not in first normal form. Examples of tables (or views) that would not meet this definition of first normal form are:
First normal form, as defined by Chris Date, permits relation-valued attributes (tables within tables). Date argues that relation-valued attributes, by means of which a column within a table can contain a table, are useful in rare cases.[16] See also{{Hatnote|For other normal forms, see the navigation bar at the bottom of the page.}}References1. ^{{cite book|title=Fundamentals of Database Systems, Fourth Edition|publisher=Pearson|date=July 2003|author1=Elmasri, Ramez |author2=Navathe, Shamkant B.|isbn=0321204484|page=315|quote=It states that the domain of an attribute must include only atomic (simple, indivisible) values and that the value of any attribute in a tuple must be a single value from the domain of that attribute.}} 2. ^{{citation|title=Further normalization of the database relational model|author=E. F. Codd|booktitle=Data Base Systems|location=Courant Institute|publisher=Prentice-Hall|date=Oct 1972|isbn=013196741X|quote=A relation is in first normal form if it has the property that none of its domains has elements which are themselves sets.}} 3. ^studytonight.com 4. ^[https://stackoverflow.com/questions/723998/can-someone-please-give-an-example-of-1nf-2nf-and-3nf-in-plain-english stackoverflow.com] 5. ^In the "real" world, that would not be a good assumption. 6. ^Codd, E. F. The Relational Model for Database Management Version 2 (Addison-Wesley, 1990). 7. ^Codd, E. F. The Relational Model for Database Management Version 2 (Addison-Wesley, 1990), p. 6. 8. ^Darwen, Hugh. "Relation-Valued Attributes; or, Will the Real First Normal Form Please Stand Up?", in C. J. Date and Hugh Darwen, Relational Database Writings 1989-1991 (Addison-Wesley, 1992). 9. ^"[F]or many years," writes Date, "I was as confused as anyone else. What's worse, I did my best (worst?) to spread that confusion through my writings, seminars, and other presentations." Date, C. J. ["What First Normal Form Really Means"] in Date on Database: Writings 2000-2006 (Springer-Verlag, 2006), p. 108 10. ^Date, C. J. ["What First Normal Form Really Means"] p. 112. 11. ^{{cite book|author=C.J. Date|title=SQL and Relational Theory: How to Write Accurate SQL Code|url=https://books.google.com/books?id=BCjkCgAAQBAJ&pg=PA50|accessdate=31 October 2018|date=6 November 2015|publisher="O'Reilly Media, Inc."|isbn=978-1-4919-4115-7|pages=50–}} 12. ^Date, C. J. ["What First Normal Form Really Means"] pp. 127–128. 13. ^Such views cannot be created using SQL that conforms to the 2003 standard. 14. ^"Codd first defined the relational model in 1969 and didn't introduce nulls until 1979" Date, C. J. SQL and Relational Theory (O'Reilly, 2009), Appendix A.2. 15. ^The third of Codd's 12 rules states that "Null values ... [must be] supported in a fully relational DBMS for representing missing information and inapplicable information in a systematic way, independent of data type." Codd, E. F. "Is Your DBMS Really Relational?" Computerworld, October 14, 1985. 16. ^Date, C. J. ["What First Normal Form Really Means"] pp. 121–126. Further reading{{Refbegin}}
1 : Database normalization |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。