Solved

Data Base model

Posted on 2012-04-02
1
434 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
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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now