Database Design: An Example of the Relationship Between a Credit Card and a Credit Card Type

A common example that will help me better understand the relationship with the database:

3 tables:

| Credit Card |
| ID          |
| Card #      |

| Credit Card Type |
| ID               |
| Type             |

where CreditCardType.Type can be AMEX, Visa, MasterCard.

| Customer |
| (PK) ID  |

1.) It seems that I do not need an ID field for CreditCardType, because Type is the primary key defactor. Is it useful to have a numeric field for a PC, even if there is a unique varchar?

2.) Since each credit card must have one and only type ... Do I establish a 1: 1 relationship between credit card and type of credit card?

3.) 0, 1 . 1: n . , MySQL Workbench Customer.ID Customer.PersonTypeID . , , Customer.ID . FK?

| Credit Card      | 
| (PK) ID          |
| Card #           |
| (PK) Customer.ID |
| (PK) Customer.PersonType |

| Credit Card      | 
| (PK) ID          |
| Card #           |
| (FK) Customer.ID |
+3
2

:

Customer
    Id int

CreditCardType:
    Id int
    TypeName varchar (eg. Visa)

CreditCard
    Id int
    CreditCardTypeId int
    CustomerId int
    CardNumber varchar

, , , TypeName , , , . , CreditCardType "American Express", CreditCardType, CreditCard . , .

+1

. ( ), . DB modding.

0

Source: https://habr.com/ru/post/1763055/


All Articles