Jump to content

DB design for inventory system


raju143

Recommended Posts

As of now there are 10 branches and it will expand in the future. Books are supplied to these branches and these books will be given to the students at each branch. The book a student gets depends upon the course he is undergoing. The customer wants the inventory list branch wise and at the same time he also wants log of when books were added and when books were given to students.

 

I am not able to think of a DB table design which suits the customers requirement. Any ideas?

Link to comment
Share on other sites

It's a basic many-to-many relationship.

 


 

branches

branch_id, unsigned integer, primary key

* etc. *

 

students

student_id, unsigned integer, primary key

branch_id, unsigned integer, key

* etc. *

 

books

book_id, unsigned integer, primary key

* etc. *

 

student_book

student_id, unsigned integer, key

book_id, unsigned integer, key

created_at, datetime

 


 

If Joe has user ID 142 then you can get his books like this:

SELECT b.*, join.created_at AS book_given
 FROM books AS b
 INNER JOIN student_book AS join
   ON b.book_id = join.book_id
 WHERE join.student_id = 142;

Link to comment
Share on other sites

I don't see "course" in that data model, and it's the course that dictates which books they get.

 

I'm thinking an entity relationship along these lines

 

[pre]

      course                        book  ------<  stockreceipt  >-----  branch

      |  |                        |  |                                  |

      |  +---< course_book >-------+  |                                  |

      |                                |                                  |

      |                                |                                  |

      ^                                ^                                  |

    student ----------------------<  issue  >-----------------------------+

 

[/pre]

Link to comment
Share on other sites

Thanx Daniel0 & Barand for your response.

 

I am a newbie to database design and structures. I can understand basic SQL queries. The query which is mentioned here, the database structure and the many-to-many relationship are all new to me.

 

Can anyone suggest me a good resource which will help me to understand the above mentioned stuff and also which will help me to design and achieve complex database designs.

 

Thanks in advance.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.