【正文】
數(shù)據(jù)庫。 定義實體 首先,設計者確定數(shù)據(jù)庫應用程序范圍內(nèi)的所有實體。實體將被巧妙的轉(zhuǎn)化為數(shù)據(jù)表。它 們將稱為 EMP(員工)表, DEPT(部門)表, SALGRADE(工資水平)表和 BONUS(獎金)表。通常,設計者通常將每個實體同其他實體配對,并目考慮:“兩者之間是否存在關聯(lián)呢?”實體間的某些關聯(lián)是明顯的,某些不是。如果事物間的關系原則是用來約束某個部門的工資水平的,就可能需要一個新的實體來說明 工資水平和部門之間的關聯(lián)。 關系表:是一個數(shù)據(jù)庫表,其中保存著另外兩個表的行(記錄)間的有效結合,并且通常強調(diào)了事物間的關系原則。 通常,關系數(shù)據(jù)庫間有二種關聯(lián)方式: 意思是對于每個給出的現(xiàn)有實體(即父實體)都有一個或多個現(xiàn)有的另一個實體(即子實體)與之相關聯(lián)。這樣,部門實體和員工實體間的關聯(lián)就是一對多關聯(lián)。一對一關聯(lián):在一個一對一關聯(lián)中,表中的一行只關聯(lián)另一個表中的一行甚至 0行。例如,一個員工表可能保存了所有員工的信息,而全職表、兼職表和承包人表則分別保存全職員工、兼職員工和承包人的信息。這種關系不像一對多關聯(lián)那么常見,因為如果一個實體與另一個實體總有對應行,在大多數(shù)情況下,兩個實體中的屬性只在一個實體內(nèi)出現(xiàn)就可以了。多對多關聯(lián):在多對多關聯(lián)中,表的一行可能 對應另一個表的許多行,反之亦然。例如,在一個學籍注冊數(shù)據(jù)庫中,學生表與班級表之間有一個多對多關聯(lián) —— 一個學生可能聽一門或多門課程,并目一個班級也可能有一個或多個學生。 指定實體屬性 一旦設計者定義了實體間關聯(lián),下一步就是去指定每個實體的屬性。 重復步驟:我們?nèi)匀辉谠? 在定義了實體、關聯(lián)以及屬性之后,設計者往往要多重復幾次數(shù)據(jù)建模過程。比如,當討論飾品庫存表和與它相關的客戶訂單時,就會發(fā)現(xiàn)需要制定一個送貨約束表。邏輯數(shù)據(jù)庫的設計過程不會牽涉實際執(zhí)行中的問題。結果,設計就可能需要再次構想以求得理想的數(shù)據(jù)庫存運行與預算和進度之間的平衡。s go over the basic ponents of a traditional relational database system and look at how a relational database is designed. Once you have a solid understanding of what rows, columns, tables, and relationships are, you39。s query language. For example, a table with information about employees might have a column called LAST_NAME that contains all of the employees39。ll learn about database design in the following sections, but let39。 they are blank. A relational database can enforce the rule that fields in a column may or may not be empty. In this case, it makes sense for an employee who is not in the Sales department to have a blank Commission field. It also makes sense for the president of the pany to have a blank Manager field, since that employee doesn39。s take a closer look at each step in the datamodeling process. Defining the Entities First, the designer identifies all of the entities within the scope of the database entities are the persons, places, or things that are important to the anization and need to be tracked in the database. Entities will most likely translate neatly to database tables. For example, for the first version of Scott39。 some are not. In the widget pany database, there is most likely a relationship between EMP and DEPT, but depending on the business rules, it is unlikely that the DEPT and SALGRADE entities are related. If the business rules were to restrict certain salary grades to certain departments, there would most likely be a new entity that defines the relationship between salary grades and departments. This entity would be known as an associative or intersection table and would contain the valid binations of salary grades and departments. Associative Table:A database table that stores the valid binations of rows from two other tables and usually enforces a business rule. An associative table resolves a manytomany relationship. In general, there are three types of relationships in a relational database: Onetomany The most mon type of relationsh