Solved

Data Base model

Posted on 2012-04-02
1
441 Views
Last Modified: 2012-04-15
Hi

I want to store and retrieve data. The data represent invoice that has may simple item or complex item. The invoice may have an undetermined number of items.

E.g.
Invoice 1
    Item 1
        Item 1.1
            Item 1.1.1
        Item 1.2
     Item 2
     Item 3

What is the best way to design such data base. I think about recursive table but iam not sure if that's right.


Thanks.
0
Comment
Question by:ang3lus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 24

Accepted Solution

by:
johanntagle earned 500 total points
ID: 37799315
I would go for two tables.  One for Invoice, which includes other non-item data (client, date, etc).  Then one for Invoice_Items.  Among other fields describing the item, this table will have InvoiceID (or InvoiceNumber) which will determine which invoice it belongs to, then a parent_item_id which has the value of the id of the parent item if the entry is a sub-item.  Something like:

mysql> desc invoices;
+--------------+-------------+------+-----+---------+----------------+
| Field        | Type        | Null | Key | Default | Extra          |
+--------------+-------------+------+-----+---------+----------------+
| id           | int(11)     | NO   | PRI | NULL    | auto_increment |
| invoice_date | date        | YES  |     | NULL    |                |
| client_name  | varchar(30) | YES  |     | NULL    |                |
+--------------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

mysql> desc invoice_items;
+----------------+-------------+------+-----+---------+----------------+
| Field          | Type        | Null | Key | Default | Extra          |
+----------------+-------------+------+-----+---------+----------------+
| id             | int(11)     | NO   | PRI | NULL    | auto_increment |
| invoice_id     | int(11)     | YES  |     | NULL    |                |
| item_name      | varchar(30) | YES  |     | NULL    |                |
| parent_item_id | int(11)     | YES  |     | NULL    |                |
+----------------+-------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

Open in new window

0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delete old Sharepoint backups 2 54
When to use a Unique Index? A Clustered Index? 5 76
Code not executing correctly. 3 43
Database movement 2 14
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question