How should I design my database?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Sequalit
Forum Commoner
Posts: 75
Joined: Wed Oct 12, 2005 9:57 pm
Location: Texas

How should I design my database?

Post by Sequalit »

I need to be able to store transaction data, such as a deposit or a withdrawal. Both have 3 feilds, date, desciption, and amount.

Should I create two tables, a deposit table and a withdrawal table

Or have one table called transactions, that stores both, so it will have a fourth field called type(deposit or withdrawal)

What do I have to consider with going for one or the other?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: How should I design my database?

Post by Weirdan »

I would have a single transaction table. Withdrawal records would have a negative amount, deposit - positive. This way it's easy to summarize actions taken on behalf of particular account, using sum() + group by.
Sequalit
Forum Commoner
Posts: 75
Joined: Wed Oct 12, 2005 9:57 pm
Location: Texas

Re: How should I design my database?

Post by Sequalit »

k thanks.

Also this will allow me more flexibility such as if i wanted to add a type called bill :)
Post Reply