Database Design for a Library Management System

Поділитися
Вставка
  • Опубліковано 28 лис 2024

КОМЕНТАРІ • 89

  • @DatabaseStar
    @DatabaseStar  14 днів тому

    Want to improve your database design skills? Get my Database Design project Guides here (diagrams, explanations, and SQL scripts): www.databasestar.com/dbdesign/?

  • @houstonfirefox
    @houstonfirefox 3 роки тому +4

    For those wondering, the primary key 'ID' on book table is used so that duplicate book names can be represented, with other fields to help the user differentiate which they are looking at.

    • @DatabaseStar
      @DatabaseStar  3 роки тому

      Good point! And also if the book name or anything else changes it can be updated without impacting any links to other tables.

    • @houstonfirefox
      @houstonfirefox 3 роки тому +1

      @@DatabaseStar Also a good point! Primary key changes are to be avoided at all costs. Using a surrogate key as is done here is certainly preferable to using possibly-changing data in the key. Very nice work sir!

    • @vinny142
      @vinny142 3 роки тому

      @@houstonfirefox " Primary key changes are to be avoided at all costs."
      That's a bit strong because you can define ON UPDATE CASCADE on the relations and any change in the PK value will be automatically passed to the related tables.
      This may result in an unexpected or undesirable amount of tuple-writes, but that is a different matter. You cannot break your data by changing a PK value, the "MS" bit in the RDBMS will not let you.

    • @houstonfirefox
      @houstonfirefox 3 роки тому

      @@vinny142 True and for the most part, I agree. However, many of the so-called 'professional' pieces of software I deal with perform integrity-checking on the front end (application) and inconsistent/little-to-any on the back end (database side). As such, there are many times where there is no protection against a PK change in the primary table resulting in a lot of 'orphaned' data in the related tables. At our company we recently saw this happen to our $250,000+/year CRM system which created quite a nightmare to sort out (and retroactively update). Developers are a whole other story as you know hahaha.
      Of course, one of the downsides of a surrogate key is when transporting the data between databases using a script. If the 'auto-id' or 'identity' is not disabled prior to the script running then it may result in a renumbering of the surrogate key and all of the fun that ensues after that.
      Thanks for the reply! I enjoy the discussion!

  • @IAmPhysics1
    @IAmPhysics1 2 роки тому +1

    For the fine system, one could apply a bit of accounting knowledge and keep it all in one table.
    To do this, I would structure the fines table like this:
    * (PK) id
    * (FK) Member_id
    * Loan_id //Remove FK constraint. Payments can be independent of a specific loan ID.
    * Fine_date
    * Fine_type //This is the first big change. Define whether the fine is the initial fine, or compounding interest. Some libraries do that.
    * Fine_debit //For increases to the fines owed, both initial and interest.
    * Fine_credit //For decreases to the fines owed.
    This would essentially structure the fines table to be like an accounting ledger, which is a tried and true layout for auditing any sort of money movement.

    • @DatabaseStar
      @DatabaseStar  2 роки тому

      Great idea! This does have the benefits you mentioned, such as increasing and decreasing the fine amount.

  • @DatabaseStar
    @DatabaseStar  3 роки тому +6

    If you want the SQL to create the tables in this design, you can refer to the link in the description. A few comments below had asked for this.

  • @kumarraot
    @kumarraot 2 роки тому

    Input: You can have check constraint on the fields like status, category etc. NO need to maintain another table for same.
    ALTER TABLE [TableName] ADD CONSTRAINT my_constraint CHECK (Status = 'in stock' OR status = 'borrowed')

    • @DatabaseStar
      @DatabaseStar  2 роки тому

      Yeah that’s true, you can use a check constraint. They are harder to edit or add new values to as you need to run an Alter statement instead of just editing table data. But if the possible values rarely change then it’s not that much of an issue and a check constraint would be better.

  • @karanpaul5525
    @karanpaul5525 3 роки тому +4

    How can we use this final ERD design to create the tables in SSMS? I mean how to code just by observing the final ERD?

    • @rajatssphere8781
      @rajatssphere8781 3 роки тому

      Yes! Exactly I am still figuring out how to write the create and alter table queries just by looking at the final design.
      It's so confusing

    • @DatabaseStar
      @DatabaseStar  3 роки тому +2

      Great question! I'll add the code for this to this video (perhaps as a comment with a link to it). In short, you write a range of Create Table statements, but I can see how it can be confusing.

    • @karanpaul5525
      @karanpaul5525 3 роки тому

      @@DatabaseStar thanks a lot 🙏

    • @DatabaseStar
      @DatabaseStar  3 роки тому

      @Karan Paul I've added a link to the description with the SQL code to create the tables. Hope that helps!

  • @alejandrocarmena8767
    @alejandrocarmena8767 2 роки тому +2

    Hi, very insightful video :) just one question. Since "member_id" is already found in "loan", why is it duplicated in table "fine"?

    • @DatabaseStar
      @DatabaseStar  2 роки тому +2

      Thanks! Good question. I think you're right, you don't actually need the member_id in the fine table. You can find the member that it is for by looking at the related loan record. And having it in the fine table, in my design, leaves it open for the member ID to be different which could be different.

  • @syedburhanalishah1631
    @syedburhanalishah1631 Рік тому

    Very well done Sir. It would be beneficial if you could show Identifying and Non-Identifying relations in the ERD too. I still find it difficult to grasp. Or if you could please make a video about Strong & Weak Entities and Identifying & Non-Identifying relations.

    • @DatabaseStar
      @DatabaseStar  Рік тому +1

      Thanks! I don't often come across those concepts when creating ERDs.

    • @syedburhanalishah1631
      @syedburhanalishah1631 Рік тому

      @@DatabaseStar Is that because we are now using surrogate keys in every table ?

  • @dishasolanki56
    @dishasolanki56 2 роки тому +1

    Why fine_payment is not associated with loan ? If there is something like "Find top10 books for which max fine has been paid", with the current design that is not possible.

    • @DatabaseStar
      @DatabaseStar  2 роки тому

      I chose not to relate fine_payment to loan because the fine table is already related to loan, and the fine payments could be recorded independently and be for one or many loans. But it would be just as valid to relate fine_payment to fine, which would be done by putting the fine.id into the fine_payment table.
      You could "find the top 10 books for which max fine has been paid" by joining through the member table to the fine_payment table to see the payments, but yes it would be a bit trickier.

  • @tylercondon3453
    @tylercondon3453 2 роки тому

    Very informative video! Thanks so much!

  • @rhythmrhy1380
    @rhythmrhy1380 Рік тому

    Excellent job

  • @m_forever7
    @m_forever7 3 роки тому +3

    Is there any coding available for this database ? I need it for a project.

    • @DatabaseStar
      @DatabaseStar  3 роки тому

      Hi, you can use the final design at the end of the video to create the tables. You can write a range of Create Table statements to create the tables in your database.

    • @DatabaseStar
      @DatabaseStar  3 роки тому +2

      @Meenakshi - I've added a link to the description with the SQL code to create the tables. Hope that helps!

  • @Modi_In_Canada
    @Modi_In_Canada Рік тому +1

    Let's say I have 10 copy of a book.. How can I get status of each book?

    • @DatabaseStar
      @DatabaseStar  Рік тому

      You could use a combination of the loan table and the book table to determine how many books are currently loaned out. This design doesn't track each individual copy of the book, but you could tell from this design how many of the 10 books are currently loaned out.

  • @carthai4590
    @carthai4590 5 місяців тому

    i'm a fan of yours

  • @MuhammadHuzaifaKhan-o3s
    @MuhammadHuzaifaKhan-o3s Рік тому

    How do I know that which fines are pending for the specific member?

    • @DatabaseStar
      @DatabaseStar  Рік тому

      You can select from the fine table and filter on a specific member ID. There isn't a way to link the specific payment to the specific fine, but you can calculate a total to see the outstanding balance.

  • @mehmetyasirsaher
    @mehmetyasirsaher Рік тому

    Hi sir! Thanks for the video it really helped me and I learn a lot of basics about SQL from this project. However, I failed to create queries. Could you help me? I need some examples. Thank you for everything.

    • @DatabaseStar
      @DatabaseStar  Рік тому

      Good to hear! Sure, you can check out the SQL Roadmap mentioned in the description to see how to start creating SQL queries.

  • @rajatssphere8781
    @rajatssphere8781 3 роки тому +1

    Can you provide the code for this database...only just for few tables because idk how to do that.

    • @DatabaseStar
      @DatabaseStar  3 роки тому +2

      Good idea Rajat, I'll add the code (as mentioned in another comment).

    • @DatabaseStar
      @DatabaseStar  3 роки тому +1

      @Rajat - I've added a link to the description with the SQL code to create the tables. Hope that helps!

  • @trupti6251
    @trupti6251 Рік тому

    Is it correct if we have a status in fine_payment which will contain whether the payment is due or paid ?

  • @estergreis7684
    @estergreis7684 2 роки тому

    What if there is a rule that you can't loan more than two books at the same time and if you want to loan another book you have to return one of the two books you have already loaned, how can we add this in the Entity Relationship Diagram?

    • @DatabaseStar
      @DatabaseStar  2 роки тому +3

      Good question. You could try to add a constraint for loans, but I don't think a constraint could handle that kind of logic. There are a few ways you could do this: a database trigger to check the table, a function or stored procedure that does the loan process and includes this logic, or adding the logic into the application code. I would suggest either a stored procedure on the database or in the application code.

  • @Photonsr
    @Photonsr 4 місяці тому

    Is this database normalised to 1NF, 2NF and 3NF?

    • @DatabaseStar
      @DatabaseStar  4 місяці тому

      Yes it should be normalised to 3NF.

  • @IrfanRafiq-os3ed
    @IrfanRafiq-os3ed 5 місяців тому

    please share some queries to get data from this library database

    • @DatabaseStar
      @DatabaseStar  5 місяців тому

      I can add some in the future.

  • @puneetyadav492
    @puneetyadav492 6 місяців тому

    Thank you

  • @sahilsiddiqui3210
    @sahilsiddiqui3210 Рік тому

    what about the librarian , library having differnt branch

    • @DatabaseStar
      @DatabaseStar  Рік тому

      Good ideas. Yes you can add those to this design.

  • @El-Ge
    @El-Ge 2 роки тому

    Where is the book's code which is different with book's ID, for in all libraries each books has its own book code.

    • @DatabaseStar
      @DatabaseStar  2 роки тому

      Good point. This can also be added to the book table as a separate field.

  • @PeterJoel-t6x
    @PeterJoel-t6x Рік тому

    How can I create my own database library

    • @DatabaseStar
      @DatabaseStar  Рік тому

      What do you mean? You can follow this video as an example

  • @Mzounalqarni
    @Mzounalqarni 2 роки тому

    Can you make a video to make a ER diagram for this system ?

    • @DatabaseStar
      @DatabaseStar  2 роки тому

      What do you mean by making an ER diagram? Isn’t that what this video is?

    • @Mzounalqarni
      @Mzounalqarni 2 роки тому

      @@DatabaseStar ER diagram showing the relationship and entities

    • @DatabaseStar
      @DatabaseStar  2 роки тому

      Hi Nine, this video actually shows you how to make an ER diagram for this system. At the end of the video is the final ERD, and there's a link to the ERD in the description (a PNG file)

  • @artbyvii04
    @artbyvii04 2 роки тому

    is all the ids in the diagram same.

  • @tommurd3116
    @tommurd3116 Рік тому

    Do you have dfd for this system?

  • @ugbatmagnai3567
    @ugbatmagnai3567 3 роки тому

    Do we need create entity of library staff?

    • @DatabaseStar
      @DatabaseStar  3 роки тому

      If you'd like it in the database, you can create it. It could be a good enhancement if you want to capture information about library staff.

  • @azqaf4287
    @azqaf4287 2 роки тому

    Hello sir. I am sorry if i make mistake writing in english. Sir i want to add book with its author at the same time but i do not know how to do this. Can you please give me tip

    • @DatabaseStar
      @DatabaseStar  2 роки тому

      You can insert a record into both tables if you like.

  • @nadaawad9828
    @nadaawad9828 2 роки тому

    Thanks 💖

  • @Bimmerish
    @Bimmerish Рік тому

    Hello, I have some questions how i can send a direct message to you?

    • @DatabaseStar
      @DatabaseStar  Рік тому

      Hey, I have a contact form on my website that sends me an email. It’s at www.databasestar.com

  • @manyabhutani8235
    @manyabhutani8235 2 роки тому

    what about identifying relations?

    • @DatabaseStar
      @DatabaseStar  2 роки тому

      What do you mean by identifying relations?

    • @Ahmad-ww4ue
      @Ahmad-ww4ue 2 роки тому

      @@DatabaseStar I guess she meant relationships between the tables, i.e. parent/child or 1-to-1, one-to-many, or many-to-many.

  • @theuntrainedsinger1185
    @theuntrainedsinger1185 Рік тому

    Why didn't you create a table for each copy of book? I know you didn't put it in requirements but why.

    • @DatabaseStar
      @DatabaseStar  Рік тому

      Good point, and that is something I should have created, so we can track each copy of the book.

  • @banelethabede4871
    @banelethabede4871 2 роки тому

    The link to SQL code is dead someone help me get the code please

    • @DatabaseStar
      @DatabaseStar  2 роки тому

      What happens when you click the link? I just tried it and it works. Here's the link: dbshostedfiles.s3.us-west-2.amazonaws.com/dbs/library_management_create.sql

    • @banelethabede4871
      @banelethabede4871 2 роки тому

      @@DatabaseStar Thank you, it kept loading after a while it gave an error saying host not available

  • @ellaabbasi8723
    @ellaabbasi8723 3 роки тому

    Why loan_fine relationship is one-to-many?

    • @DatabaseStar
      @DatabaseStar  3 роки тому

      It’s because there could be multiple fines for one loan. That’s just one way to design it, you could have a one to one relationship or another way.

  • @neuroglide6854
    @neuroglide6854 2 роки тому

    Just for the record man, the way you speak sucks....It is not loud enough, super soft and you have this disappearing end, which makes listening to you frustrating...

    • @DatabaseStar
      @DatabaseStar  2 роки тому +3

      Thanks for the feedback! Since recording this video I've worked to improve my audio quality (new microphone, better editing), so I hope the newer videos have better quality.
      What do you mean by "disappearing end"?