Hi all,
I'm creating a Point of Sale application, mostly to teach myself about GUI programming and obviously some more about database design
I want to achieve the following with my database;
- Store a list of products - could be large, like 10,000
- Keep track of stock levels for said products
- Store all incoming (purchases) and outgoing (sales) transactions.
I've had a search around and either I can't come up with the right search terms or I just plain can't find anyone talking about this.
My feeble attempt at a designing the schema was something along these lines;
Using MySQL because I know it (maybe I should say "have used it before" here) and because I wanted to use it's replication.
Using the above I would keep a record of each incoming transaction with positive quantities in the transactionitems table and outgoing transactions with negative quantities.
When you wanted to see a list of stock with the stock level you would have to do something which looks grossly inefficient like;
The above might work for a short period of time with a small amount of items and transactions but I feel like I am missing some basic point of database design.
If someone who can understand what I am rambling about and has a clue could enlighten me I would be very grateful.
Cheers,
hads.
I'm creating a Point of Sale application, mostly to teach myself about GUI programming and obviously some more about database design
I want to achieve the following with my database;
- Store a list of products - could be large, like 10,000
- Keep track of stock levels for said products
- Store all incoming (purchases) and outgoing (sales) transactions.
I've had a search around and either I can't come up with the right search terms or I just plain can't find anyone talking about this.
My feeble attempt at a designing the schema was something along these lines;
Code:
CREATE TABLE `items` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(255) NOT NULL default '',
`price` float(10,2) NOT NULL default '0.00',
PRIMARY KEY (`id`)
) ENGINE=MyISAM;
CREATE TABLE `transactions` (
`id` int(10) unsigned NOT NULL auto_increment,
`entered` datetime NOT NULL default '0000-00-00 00:00:00',
`status` enum('s','c') NOT NULL default 'c',
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
CREATE TABLE `transactionitems` (
`id` int(10) unsigned NOT NULL auto_increment,
`transaction` int(10) unsigned NOT NULL default '0',
`item` int(10) unsigned NOT NULL default '0',
`quantity` int(10) NOT NULL default '0',
`price` float(10,2) NOT NULL default '0.00',
PRIMARY KEY (`id`)
) ENGINE=InnoDB
Using MySQL because I know it (maybe I should say "have used it before" here) and because I wanted to use it's replication.
Using the above I would keep a record of each incoming transaction with positive quantities in the transactionitems table and outgoing transactions with negative quantities.
When you wanted to see a list of stock with the stock level you would have to do something which looks grossly inefficient like;
Code:
SELECT i.id, i.name, i.price, SUM(t.quantity) AS stock FROM items i
LEFT JOIN transactionitems t ON t.product = i.id
GROUP BY i.id
The above might work for a short period of time with a small amount of items and transactions but I feel like I am missing some basic point of database design.
If someone who can understand what I am rambling about and has a clue could enlighten me I would be very grateful.
Cheers,
hads.