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 740347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:30:20+00:00 2026-05-14T08:30:20+00:00

I’m new to relational databases and all the material I’ve read covered primary and

  • 0

I’m new to relational databases and all the material I’ve read covered primary and foreign keys, normal forms, and joins but left out to populate the database once it’s created.

How do you import a CSV file so the fields match their related table?

Say you were tying to build a beer database and had a CSV file with each line as a record.

Header: brewer, beer_name, country,
city, state, beer_category, beer_type,
alcohol_content

Record 1: Anheuser-Busch, Budweiser,
United States, St. Louis, Mo, Pale lager,
Regular,
5.0%

Record 2: Anheuser-Busch, Bud Light,
United States, St. Louis, Mo, Pale lager
Light, 4.2%

Record 3: Miller Brewing Company,
Miller Lite, United States, Milwaukee,
WI, Pale lager, Light,
4.2%

You can create a “Brewer” table and a “Beer” table. When importing how does you connect the primary keys between the tables?

  • 1 1 Answer
  • 0 Views
  • 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-14T08:30:21+00:00Added an answer on May 14, 2026 at 8:30 am

    You define Primary and Foreign key relationships when you create the tables. Once they’ve been set up you can just about forget them, unless the database throws an error if you try to do something that violates the relationships.

    For example, if you try to add a record into the child (foreign) table that does not have a value in the parent table, the database will complain, if the relationships are set up correctly.

    e.g. Adding Record 1 into the Beer table will fail unless you have already added
    Anheuser-Busch into the Brewers table.

    A suggestion on setting up your tables:

    Brewer
        id         bigint
        name       varchar(50)
        country    varchar(50)
        state      varchar(10)
        city       varchar(50)
    
    
    Beer
        id         bigint
        brewerId   bigint
        name       varchar(70)
        category   varchar(50)
        type       varchar(50)
        alcohol    decimal(3,1)
    
    Set Brewer.Id as the Primary Key of the Brewer table.
    Set Beer.Id as the Primary Key of the Beer table.
    Then create a foreign key relationship between Brewer.Id = Beer.brewerId
    

    Then manually add the brewers (because there’s not too many of them)

    Brewer
        1    Anheuser-Busch            United States    Mo    St. Louis
        2    Miller Brewing Company    United States    WI    Milwaukee
    

    Then fiddle your CSV file to replace all the brewer details with the brewer’s respective id, and use that to populate your Beer table:

    Beer
        1    1    Budweiser    Pale lager    Regular    5.0
        2    1    Bud Light    Pale lager    Light      4.2
        3    2    Miller Lite  Pale lager    Regular    4.2
    

    So: The brewerId links each beer to a brewer in the brewer table. That is the foreign key – each beer automatically gets all the brewer’s details because it’s brewerId matches the brewer’s id (and you set that relationship up when you created the tables).

    • Beer 1 (Budweiser) belongs to Brewer 1 (Anheuser-Busch)
    • Beer 2 (Bud Light) belongs to Brewer 1 (Anheuser-Busch)
    • Beer 3 (Miller Light) belongs to Brewer 2 (Miller)

    This lets you do really cool suff. Say Miller was bought by another company… all you have to do is change the details in the Brewer table, and voila – all the beers that were owned by Miller now belong to the new brewer. You can also calculate sales by Brewer, state, etc.

    The basic rule of thumb is that Primary and Foreign keys are like a Parent – Child relationship. The Child stores the Parent’s id. This way each Parent can have multiple Children. It can get a WHOLE lot more complicated, but this will give you a very good starting approach to most of your database solutions.

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

Sidebar

Related Questions

No related questions found

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.