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

  • SEARCH
  • Home
  • 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 225947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:27:49+00:00 2026-05-11T19:27:49+00:00

I have only done databases without relations, but now I need to do something

  • 0

I have only done databases without relations, but now I need to do something more serious and correct.

Here is my database design:
alt text

  1. Kunde = Customer
  2. Vare = Product
  3. Ordre = Order (Read: I want to make an order)
  4. VareGruppe = ehm..type? (Read: Car, chair, closet etc.)
  5. VareOrdre = Product_Orders

Here is my SQL (SQLite) schema:

CREATE TABLE Post (
    Postnr INTEGER NOT NULL PRIMARY KEY,
    Bynavn VARCHAR(50) NOT NULL
);

CREATE TABLE Kunde (
    CPR INTEGER NOT NULL PRIMARY KEY,
    Navn VARCHAR(50) NOT NULL,
    Tlf INTEGER NOT NULL,
    Adresse VARCHAR(50) NOT NULL,
    Postnr INTEGER NOT NULL 
    CONSTRAINT fk_postnr_post REFERENCES Post(Postnr)
);

CREATE TABLE Varegruppe (
    VGnr INTEGER PRIMARY KEY,
    Typenavn VARCHAR(50) NOT NULL
);


CREATE TABLE Vare (
    Vnr INTEGER PRIMARY KEY,
    Navn VARCHAR(50) NOT NULL,
    Pris DEC NOT NULL,
    Beholdning INTEGER NOT NULL,
    VGnr INTEGER NOT NULL
        CONSTRAINT fk_varegruppevgnr_vgnr REFERENCES Varegruppe(VGnr)
);

CREATE TABLE Ordre (
    Onr INTEGER PRIMARY KEY,
    CPR INTEGER NOT NULL
        CONSTRAINT fk_kundecpr_cpr REFERENCES Kunde(CPR),
    Dato DATETIME NOT NULL,
    SamletPris DEC NOT NULL
);

CREATE TABLE VareOrdre (
    VareOrdreID INTEGER PRIMARY KEY,
    Onr INTEGER NOT NULL
        CONSTRAINT fk_ordrenr_onr REFERENCES Ordre(Onr),
    Vnr INTEGER NOT NULL 
        CONSTRAINT fk_varevnr_vnr REFERENCES Vare(Vnr),
    Antal INTEGER NOT NULL
);

It should work correctly.

But I am confused about Product_Orders.

How do I create an order? For example, 2 products using SQL INSERT INTO?
I can get nothing to work.

So far:

Only when I manually insert products and data into Product_Orders and then add that data to Orders = which makes it complete. Or the other way around (create an order in with 1 SQL, then manually inserting products into Product_orders - 1 SQL for each entry)

  • 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-11T19:27:49+00:00Added an answer on May 11, 2026 at 7:27 pm

    You should first create an order and then insert products in the table Product_Orders. This is necessary because you need an actual order with an id to associate it with the table Product_Orders.

    You always should create a record in the foreign-key table before being able to create one in your current table. That way you should create a “Post”, customer, type, product, order and product_order.

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

Sidebar

Ask A Question

Stats

  • Questions 109k
  • Answers 109k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The full-text search feature of MySQL, which is generally available… May 11, 2026 at 9:29 pm
  • Editorial Team
    Editorial Team added an answer I think you may be approaching the problem from the… May 11, 2026 at 9:29 pm
  • Editorial Team
    Editorial Team added an answer The Html helper function takes a 'first empty value' parameter… May 11, 2026 at 9:29 pm

Related Questions

I have a pair of SQL Servers at different webhosts, and I'm looking for
I have a sql query with 50 parameters, such as this one. DECLARE @p0
Lots of developers think that testing private methods is a bad idea. However, all
I have a database file that is generated on a PC using Sqlite. This
I have been getting an error message that I can't resolve. It originates from

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.