0 valutazioniIl 0% ha trovato utile questo documento (0 voti)
20 visualizzazioni1 pagina
The document describes normalizing a database table by splitting an order form table into two tables - order_header and order_detail. The order_detail table has a composite primary key of order_number and product_number. It is noted that the design violates 2nd normal form because the product_description only depends on the product_number part of the primary key. To resolve this, the document proposes extracting product_description into a new product_catalog table, with product_number as the primary key and a foreign key in product_order. This eliminates redundancy and allows storing product information separately from orders.
The document describes normalizing a database table by splitting an order form table into two tables - order_header and order_detail. The order_detail table has a composite primary key of order_number and product_number. It is noted that the design violates 2nd normal form because the product_description only depends on the product_number part of the primary key. To resolve this, the document proposes extracting product_description into a new product_catalog table, with product_number as the primary key and a foreign key in product_order. This eliminates redundancy and allows storing product information separately from orders.
The document describes normalizing a database table by splitting an order form table into two tables - order_header and order_detail. The order_detail table has a composite primary key of order_number and product_number. It is noted that the design violates 2nd normal form because the product_description only depends on the product_number part of the primary key. To resolve this, the document proposes extracting product_description into a new product_catalog table, with product_number as the primary key and a foreign key in product_order. This eliminates redundancy and allows storing product information separately from orders.
The solution is to split order_form into order_header and order_detail with
the repeating columns moved down into order_detail. The order_number col- umn in order_detail is a foreign key pointing to the order_header table; this makes order_detail a repeating child of order_header. The product_number col- umn is part of the primary key to identify different detail rows that are part of the same order. CREATE TABLE order_header ( order_number INTEGER NOT NULL PRIMARY KEY, client_name VARCHAR ( 100 ) NOT NULL, shipping_address VARCHAR ( 1000 ) NOT NULL, salesperson_name VARCHAR ( 100 ) NOT NULL, salesperson_phone VARCHAR ( 100 ) NOT NULL, salesperson_commission NUMERIC ( 6, 3 ) NOT NULL );
CREATE TABLE order_detail (
order_number INTEGER NOT NULL REFERENCES order_header, product_number INTEGER NOT NULL, product_description VARCHAR ( 100 ) NOT NULL, requested_quantity INTEGER NOT NULL, estimated_shipping_date DATE NOT NULL, PRIMARY KEY ( order_number, product_number ) ); The number of order_detail rows in a single order is now truly variable with no artificial maximum. Each order_detail row can be processed like any other in an application program loop, and the number of rows can be easily counted.
1.16.2 Second Normal Form
Second Normal Form (2NF) eliminates any non-key column that only depends on part of the primary key instead of the whole key. The order_detail table has a two-column primary key (order_number and product_number), but the prod- uct_description column only depends on product_number. This violates Second Normal Form. One problem here is redundancy: If a product description changes, it must be changed in every order_detail row containing that value. Another problem is theres no place to store a new product number and description until that prod- uct is ordered. The solution is to move product_description up into a new table, prod- uct_catalog, which holds information about products separate from orders. The order_detail table becomes product_order, and the product_number column becomes a foreign key pointing to the new product_catalog table. CREATE TABLE order_header ( order_number INTEGER NOT NULL PRIMARY KEY, client_name VARCHAR ( 100 ) NOT NULL, shipping_address VARCHAR ( 1000 ) NOT NULL, salesperson_name VARCHAR ( 100 ) NOT NULL, salesperson_phone VARCHAR ( 100 ) NOT NULL, salesperson_commission NUMERIC ( 6, 3 ) NOT NULL );
CREATE TABLE product_catalog (
product_number INTEGER NOT NULL PRIMARY KEY, product_description VARCHAR ( 100 ) NOT NULL );
CREATE TABLE product_order (
order_number INTEGER NOT NULL REFERENCES order_header,