Skip to main content

3. Entity Relationship Diagram

Sơ đồ thực thể mối quan hệ trong CSDL

Explanation:
  1. The Customer entity has a one-to-many relationship with the Order entity, indicating that a customer can place multiple orders.
  2. The Employee entity has a one-to-many relationship with the Order entity, indicating that an employee can process multiple orders.
  3. The Order entity has a one-to-many relationship with the OrderDetails entity, indicating that an order can include multiple order details.
  4. The OrderDetails entity has a one-to-many relationship with the Product entity, indicating that each order detail describes a single product.
  5. The Product entity has a many-to-one relationship with the Category entity, indicating that each product belongs to a single category.
  6. The Product entity has a many-to-one relationship with the Supplier entity, indicating that each product is supplied by a single supplier.

Categories

IdColumn NameData TypeNullKeyDefaultConstraint
1IdintPKAUTONUMBER
2Namenvarchar(50)UNIQUE
3Descriptionnvarchar(500)yes

Sample data:

IdNameDescription
1BooksCategory for all types of books
2ElectronicsCategory for electronic devices
3ClothingCategory for clothing items
4Home GoodsCategory for items used in the home
5BeautyCategory for cosmetic and personal care products

Suppliers

IdColumn NameData TypeNullKeyDefaultConstraint
1IdintPKAUTONUMBER
2Namenvarchar(100)
3Emailvarchar(50)UNIQUE
4PhoneNumbervarchar(50)UNIQUE
5Addressnvarchar(500)

Sample data:

IdNameEmailPhoneNumberAddress
1Supplier Asuppliera@example.com(555) 555-1234123 Main St, USA
2Supplier Bsupplierb@example.com(555) 555-5678456 Elm St, USA
3Supplier Csupplierc@example.com(555) 555-9012789 Oak St, USA
4Supplier Dsupplierd@example.com(555) 555-34561011 Pine St, USA
5Supplier Esuppliere@example.com(555) 555-78901213 Maple St, USA

Customers

IdColumn NameData TypeNullKeyDefaultConstraint
1IdintPKAUTONUMBER
2FirstNamenvarchar(50)
3LastNamenvarchar(50)
4Emailvarchar(50)UNIQUE
5PhoneNumbervarchar(50)UNIQUE
6Addressnvarchar(500)
7Birthdaydatetimeyes

Sample data:

IdFirstNameLastNameEmailPhoneNumberAddressBirthday
1JohnSmithjohnsmith@example.com0905-555-123123 Main St, USA1990-01-01
2JaneDoejanedoe@example.com0905-555-567456 Elm St, USA1985-03-15
3MikeJohnsonmikejohnson@example.com0905-555-901789 Oak St, USA1995-11-23
4SarahLeesarahlee@example.com0905-555-3451011 Pine St, USA1982-06-10
5AlexKimalexkim@example.com0905-555-7891213 Maple St, USA1992-12-31

Employees

IdColumn NameData TypeNullKeyDefaultConstraint
1IdintPKAUTONUMBER
2FirstNamenvarchar(50)
3LastNamenvarchar(50)
4Emailvarchar(50)UNIQUE
5PhoneNumbervarchar(50)UNIQUE
6Addressnvarchar(500)
7Birthdaydatetimeyes

Sample data:

IdFirstNameLastNameEmailPhoneNumberAddressBirthday
1DavidJohnsondavidjohnson@example.com0905-555-123123 Main St, USA1980-05-15
2LisaSmithlisasmith@example.com0905-555-567456 Elm St, USA1987-09-21
3MichaelBrownmichaelbrown@example.com0905-555-901789 Oak St, USA1992-02-28
4SarahDavissarahdavis@example.com0905-555-3451011 Pine St, USA1985-12-07
5KevinWilsonkevinwilson@example.com0905-555-7891213 Maple St, USA1994-06-30

Products

IdColumn NameData TypeNullKeyDefaultConstraint
1IdintPKAUTONUMBER
2Namenvarchar(100)
3Pricemoneyn > 0
4Discountdecimal(18,2)00 <= n <= 90
5Stockdecimal(18,2)0n >= 0
6Descriptionnvarchar(max)yes
7CategoryIdintFKRefrence to Categories (Id)
8SupplierIdintFKRefrence to Suppliers (Id)

Sample data:

IdNamePriceDiscountStockDescriptionCategoryIdSupplierId
1Product A10.990.00100Description of Product A21
2Product B19.990.2050Description of Product B12
3Product C5.990.00200Description of Product C33
4Product D49.990.1010Description of Product D41
5Product E29.990.0575Description of Product E22

Orders

IdColumn NameData TypeNullKeyDefaultConstraint
1IdintPKAUTONUMBER
2CreatedDatedatetimeNOW
3ShippedDatedatetimeyesn > CreatedDate
4Statusvarchar(50)WAITINGn in ['WAITING', 'COMPLETED', 'CANCELED']
5Descriptionnvarchar(max)
6ShippingAddressnvarchar(500)yes
7ShippingCitynvarchar(50)
8PaymentTypevarchar(20)CASHn in ['CASH', 'CREDIT CARD']
9CustomerIdintFKRefrence to Customers (Id)
10EmployessIdintFKRefrence to Employees (Id)

Sample data:

IdCreatedDateShippedDateStatusDescriptionShippingAddressShippingCityPaymentTypeCustomerIdEmployeeId
12022-01-152022-01-20CompletedOrder #1123 Main St, USAAnytownCredit Card13
22022-02-102022-02-15CompletedOrder #2456 Elm St, USAAnytownCash22
32022-03-052022-03-08CompletedOrder #3789 Oak St, USAAnytownCredit Card34
42022-04-012022-04-05CompletedOrder #41011 Pine St, USAAnytownCash15
52022-05-10WaitingOrder #5Credit Card21

Order Details

IdColumn NameData TypeNullKeyDefaultConstraint
1OrderIdintPK + FKRefrence to Orders (Id)
2ProductIdintPK + FKRefrence to Products (Id)
3Quantitydecimal(18,2)n > 0
4Pricedecimal(18,2)n > 0
5Discountdecimal(18,2)0 <= n <=90

Sample data:

OrderIdProductIdQuantityPriceDiscount
11210.990.00
1315.990.00
22119.990.20
24249.990.10
31310.990.00
35229.990.05