1. Trang chủ
  2. » Công Nghệ Thông Tin

Database Modeling & Design Fourth Edition- P32 pdf

5 221 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 165,24 KB

Nội dung

142 CHAPTER 7 An Example of Logical Database Design Figure 7.2 Conceptual data model diagram for UML Table 7.2 Results of the Analysis of the Conceptual Data Model ER Construct FDs Customer(many): Job(one) cust-no -> job-title Order(many): Customer(one) order-no -> cust-no Salesperson(many): Department(one) sales-id -> dept-no Item(many): Department(one) item-no -> dept-no Order(many): Item(many): Salesperson(one) order-no,item-no->sales-id Order(many): Department(many): Salesperson(one) order-no,dept-no-> sales-id Customer SalespersonOrder Job Department order-dept-sales Item * *1 has 1 1 * * * *1 1 1 * places hires 1 contains order- item- sales Teorey.book Page 142 Saturday, July 16, 2005 12:57 PM 7.2 Logical Design 143 create table customer (cust_no char(6), job_title varchar(256), primary key (cust_no), foreign key (job_title) references job on delete set null on update cascade); create table job (job_no char(6), job_title varchar(256), primary key (job_no)); create table order (order_no char(9), cust_no char(6) not null, primary key (order_no), foreign key (cust_no) references customer on delete set null on update cascade); create table salesperson (sales_id char(10) sales_name varchar(256), dept_no char(2), primary key (sales_id), foreign key (dept_no) references department on delete set null on update cascade); create table department (dept_no char(2), dept_name varchar(256), manager_name varchar(256), primary key (dept_no)); create table item (item_no char(6), dept_no char(2), primary key (item_no), foreign key (dept_no) references department on delete set null on update cascade); Teorey.book Page 143 Saturday, July 16, 2005 12:57 PM 144 CHAPTER 7 An Example of Logical Database Design create table order_item_sales (order_no char(9), item_no char(6), sales_id varchar(256) not null, primary key (order_no, item_no), foreign key (order_no) references order on delete cascade on update cascade, foreign key (item_no) references item on delete cascade on update cascade, foreign key (sales_id) references salesperson on delete cascade on update cascade); create table order_dept_sales (order_no char(9), dept_no char(2), sales_id varchar(256) not null, primary key (order_no, dept_no), foreign key (order_no) references order on delete cascade on update cascade, foreign key (dept_no) references department on delete cascade on update cascade, foreign key (sales_id) references salesperson on delete cascade on update cascade); Note that it is often better to put foreign key definitions in separate (alter) statements. This prevents the possibility of getting circular defini- tions with very large schemas. This process of decomposition and reduction of tables moves us closer to a minimum set of normalized (BCNF) tables, as shown in Table 7.3. The reductions shown in this section have decreased storage space and update cost and have maintained the normalization of BCNF (and thus 3NF). On the other hand, we have potentially higher retrieval cost—given the transaction “list all job_titles,” for example—and have increased the potential for loss of integrity because we have eliminated simple tables with only key attributes. Resolution of these trade-offs depends on your priorities for your database. The details of indexing will be covered in the companion book, Phys- ical Database Design. However, during the logical design phase of defin- ing SQL tables, it makes sense to start considering where to create indexes. At a minimum, all primary keys and all foreign keys should be Teorey.book Page 144 Saturday, July 16, 2005 12:57 PM 7.3 Summary 145 indexed. Indexes are relatively easy to implement and store, and make a significant difference in reducing the access time to stored data. 7.3 Summary In this chapter, we developed a global conceptual schema and a set of SQL tables for a relational database, given the requirements specification for a retail store database. The example illustrates the database life cycle steps of conceptual data modeling, global schema design, transforma- tion to SQL tables, and normalization of those tables. It summarizes the techniques presented in Chapters 1 through 6. Table 7.3 Decomposition and Reduction of Tables Table Primary key Likely non-keys customer cust_no job_title, cust_name, cust_address order order_no cust_no, item_no, date_of_purchase, price salesperson sales_id dept_no, sales_name, phone_no item item_no dept_no, color, model_no order_item_sales order_no,item_no sales_id order_dept_sales order_no,dept_no sales_id Teorey.book Page 145 Saturday, July 16, 2005 12:57 PM Teorey.book Page 146 Saturday, July 16, 2005 12:57 PM . relational database, given the requirements specification for a retail store database. The example illustrates the database life cycle steps of conceptual data modeling, global schema design, transforma- tion. trade-offs depends on your priorities for your database. The details of indexing will be covered in the companion book, Phys- ical Database Design. However, during the logical design phase of defin- ing SQL. order-no -> cust-no Salesperson(many): Department(one) sales-id -> dept-no Item(many): Department(one) item-no -> dept-no Order(many): Item(many): Salesperson(one) order-no,item-no->sales-id Order(many):

Ngày đăng: 05/07/2014, 05:20

TỪ KHÓA LIÊN QUAN