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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:57:36+00:00 2026-06-04T06:57:36+00:00

I want to create a database in SQLite with two tables: Customer and Orders.

  • 0

I want to create a database in SQLite with two tables: Customer and Orders. Each Customer can have many Orders; (I understand that’s a one-to-many relationship). Each Order can have many “line items” (a line item is a specific order for an “item”), in addition to the credit card info, terms and shipping info (non-address type info). I need the ability to find all of the orders for any particular customer, but do not have to find the customer based on an order.

This is what I have so far for the Customer table:

[db executeUpdate:@"CREATE TABLE IF NOT EXISTS CustData ("
 "BUS_NAME TEXT PRIMARY KEY NOT NULL, "
 "EMAIL TEXT, "
 "PHONE TEXT, "
 "SHOP_NAME TEXT, "
 "SHOP_ADDR1 TEXT, "
 "SHOP_ADDR2 TEXT, "
 "SHOP_CITY_STATE TEXT, "
 "SHOP_ZIP TEXT, "
 "SHIP_NAME TEXT, "
 "SHIP_ADDR1 TEXT, "
 "SHIP_ADDR2 TEXT, "
 "SHIP_CITY_STATE TEXT, "
 "SHIP_ZIP TEXT, "
 "NOTES TEXT)"];

This is what I have for the Order table:

[db executeUpdate:@"CREATE TABLE Orders ("
 "CUST_ID TEXT REFERENCES CustData, "
 "ORDER_NBR TEXT, "
 "SALES_NAME TEXT, "
 "CREDIT_CARD TEXT, "
 "EXP_DATE TEXT, "
 "CID TEXT, "
 "NOTES TEXT, "
 "PCS INTEGER, "
 "PATTERN TEXT, "
 "STYLE_NAME TEXT, "
 "PRICE DECIMAL)" ];

PCS, Pattern, Style_Name and Price are considered the “line items”.

My question is: is the correct way to define these tables with regard to the “line items”, or is there a better way?

  • 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-06-04T06:57:37+00:00Added an answer on June 4, 2026 at 6:57 am

    Your design for line items is not correct.

    Consider that just as one customer has one or more orders, each order has one or more line items. Therefore, you should have one table for the order itself and a separate table for line items. The only repeated columns between these two tables should be the column (or columns) that uniquely identify an order.

    In the design you showed, this would mean splitting out PCS, Pattern, Style_Name, and Price into the line items table along with either Order_Nbr (if that alone is sufficient to identify an order) or else Cust_ID and Order_Nbr.

    Also consider that one customer may have orders for different shipping addresses, that the shipping address or billing address may change over time, and that shipping address and billing address are really simply instances of the same entity (kind of thing) and you can see that you might well need a separate table to hold addresses that are linked to customers.

    There are other issues you might want to consider as well (such as the advisability of storing credit card information), but this should get you started.

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

Sidebar

Related Questions

I want to create a large database of GPS coordinates that can be queried
I have a SQLite database, and several tables within that datbase. I am developing
In my application I have a sqlite database that looks like this: CREATE TABLE
I want to create an SQL database for a phonegap application that i am
I want to create a new row in my database on a table that
I want to create an SQL script that creates a database. Right now, I
I want to create a two level ExpandableListView from a local database. The group
If you want to pre-populate a database (SQLite) in Android, this is not that
Say I want to create a database using the Android SDK's sqlite tool. What
Let's say I have a database with two tables Persons and PhoneNumbers , where

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.