Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1042737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:33:24+00:00 2026-05-16T15:33:24+00:00

A generic example that will help me understand database relations better: 3 tables: |

  • 0

A generic example that will help me understand database relations better:

3 tables:

| Credit Card |
| ID          |
| Card #      |

| Credit Card Type |
| ID               |
| Type             |

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

| Customer |
| (PK) ID  |

1.) It seems that I don’t need an ID field for CreditCardType because the Type is the Primary Key defacto. Is it beneficial to have a numeric field for a PK, even though there is a varchar that is unique?

2.) Because each credit card has to have one, and only, type… Do I setup a 1:1 identifying relationship between Credit Card and Credit Card Type?

3.) A customer can have 0, 1, or more credit cards. So I create a 1:n relationship between Credit Card and Customer. When I do that, MySQL Workbench adds the Customer.ID field and the Customer.PersonTypeID field as primary keys. Is that what I should be doing, or do I only need to add the Customer.ID field as a PK. Or should it be a FK?

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

or

| Credit Card      | 
| (PK) ID          |
| Card #           |
| (FK) Customer.ID |
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:33:25+00:00Added an answer on May 16, 2026 at 3:33 pm

    I would do it like this:

    Customer
        Id int
    
    CreditCardType:
        Id int
        TypeName varchar (eg. Visa)
    
    CreditCard
        Id int
        CreditCardTypeId int
        CustomerId int
        CardNumber varchar
    

    Eventhough you could say that a creditcard type does not need an id since the TypeName is unique, it’s better to have foreign key columns that are numbers since they take up less disk space. Imagine that you had a CreditCardType “American Express” which was the primary key of the CreditCardType, you would have to use that value in the CreditCard table for each row. If you have millions of registered credit cards it would take up quite some space to store the string for each row.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to compile a simple example of generic classes / type patterns (see
Suppose I have written a decorator that does something very generic. For example, it
The Generic Methods tutorial has this helpful example: public <T extends E> boolean addAll(Collection<T>
I have (for example) Dictionary of different generic types ( d1, d2, d3, d4
I should probably not ask a generic question with a specific example, but I
If say I have some generic class, for example: public class Attribute<T> { }
This is a very generic 'best practice' question, but here's an example. Let's say
Many programming languages share generic and even fairly universal features. For example, if you
I have this simple example: using System; using System.Collections.Generic; namespace ConsoleApplication1 { class Program
I am trying to create a generic formatter/parser combination. Example scenario: I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.