Sobes.tech
Senior

Design a data structure for a banking system: a client can have multiple cards (debit, credit), each linked to an account, and clients can also have accounts without cards. Use three tables.

sobes.tech AI

Answer from AI

For the described banking system, three tables can be used: Clients, Accounts, and Cards.

  • Clients — stores information about clients.

    • ClientID (PK)
    • Name
    • other client data
  • Accounts — stores accounts, which can be with or without linked cards.

    • AccountID (PK)
    • ClientID (FK) — link to client
    • AccountType (e.g., "savings", "checking")
    • Balance
  • Cards — stores information about cards, each card linked to one account.

    • CardID (PK)
    • AccountID (FK) — link to account
    • CardType ("debit", "credit")
    • CardNumber

Thus, a client can have multiple accounts, some of which may have cards, and some may not. Each card is linked to one account.

Example of relationships:

Clients (1) --- (N) Accounts (1) --- (N) Cards