Unit 2 Assignment
Unit 2 Assignment
---
**Reasoning**:
- **Customer**, **Order**, and **Product** are fundamental entities for tracking users,
transactions, and inventory.
- **OrderDetail** resolves the many-to-many relationship between `Order` and `Product` by
breaking it into two one-to-many relationships.
---
**Reasoning**:
- Composite keys (e.g., `OrderDetail`) are used when a single attribute cannot uniquely identify
a record.
---
1. **Customer → Order**
- **Cardinality**: 1:N (One-to-Many).
- **Reasoning**: A customer can place multiple orders, but each order belongs to **one**
customer.
2. **Order → OrderDetail**
- **Cardinality**: 1:N (One-to-Many).
- **Reasoning**: An order can include multiple products (via `OrderDetail`), but each line
item is tied to **one** order.
3. **Product → OrderDetail**
- **Cardinality**: 1:N (One-to-Many).
- **Reasoning**: A product can appear in multiple orders, but each `OrderDetail` entry refers
to **one** product.
4. **Product → Category**
- **Cardinality**: N:1 (Many-to-One).
- **Reasoning**: Many products belong to **one** category (e.g., 100 products in the
"Electronics" category).
5. **Customer → ShippingAddress**
- **Cardinality**: 1:N (One-to-Many).
- **Reasoning**: A customer can save **multiple** addresses (e.g., home, office).
6. **Order → ShippingAddress**
- **Cardinality**: N:1 (Many-to-One).
- **Reasoning**: Multiple orders can use the **same** shipping address (e.g., recurring
orders to the same location).
---
### **d. Additional Requirements**
**Requirement 1: Payment Processing**
- **Entities**:
- **Payment**: `PaymentID` (PK), `OrderID` (FK), `PaymentMethod`, `Amount`,
`TransactionDate`.
- **Relationships**:
- **Order → Payment**: 1:1 (One-to-One).
- **Reasoning**: Each order has **one** payment, and each payment corresponds to
**one** order.
---
```plaintext
Customer (1) ────< Places >──── (N) Order
│
│
< Maintains >──── (N) ShippingAddress
│
< Writes >──── (N) Review
**Symbols**:
- **Crow’s Foot (N)**: Represents the "many" side.
- **Single Line (1)**: Represents the "one" side.
**Explanation**:
- **Customer** places **many** orders (1:N).
- **Order** contains **many** products via `OrderDetail` (1:N).
- **Product** belongs to **one** category (N:1).
- **Customer** maintains **many** addresses (1:N).
- **Order** uses **one** shipping address (N:1).
- **Payment** is a 1:1 relationship with `Order`.
- **Review** connects to both `Customer` and `Product` in 1:N relationships.
---
1. **Conceptual Design**:
- **Focus**: High-level structure (entities, attributes, relationships).
- **Example**: Defines `Customer` with attributes like `Email` but does not specify data
types.
- **Purpose**: Facilitates communication between stakeholders.
2. **Physical Design**:
- **Focus**: Implementation details (data types, indexes, storage).
- **Example**: Converts `Email` to `VARCHAR(255) NOT NULL UNIQUE` and adds an index on
`CustomerID` for faster queries.
- **Purpose**: Optimizes performance and storage for the specific database system (e.g.,
MySQL, PostgreSQL).
**Key Difference**:
- **Conceptual** = **What** the database includes.
- **Physical** = **How** the database is built.
---
### **Summary**
This design ensures:
1. **Scalability**: Supports growing customers, orders, and products.
2. **Data Integrity**: Avoids redundancy (e.g., using `CategoryID` instead of repeating category
names).
3. **Functionality**: Handles payments, reviews, and multiple shipping addresses.
The E-R diagram visually organizes these relationships, making the system easy to understand
and implement.