Database Design for a Library Management System

  Рет қаралды 74,353

Database Star

Database Star

Күн бұрын

Пікірлер: 88
@DatabaseStar
@DatabaseStar 2 жыл бұрын
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.
@IAmPhysics1
@IAmPhysics1 2 жыл бұрын
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.
@houstonfirefox
@houstonfirefox 3 жыл бұрын
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 жыл бұрын
@@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!
@alejandrocarmena8767
@alejandrocarmena8767 Жыл бұрын
Hi, very insightful video :) just one question. Since "member_id" is already found in "loan", why is it duplicated in table "fine"?
@DatabaseStar
@DatabaseStar Жыл бұрын
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.
@karanpaul5525
@karanpaul5525 2 жыл бұрын
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 2 жыл бұрын
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 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 2 жыл бұрын
@@DatabaseStar thanks a lot 🙏
@DatabaseStar
@DatabaseStar 2 жыл бұрын
@Karan Paul I've added a link to the description with the SQL code to create the tables. Hope that helps!
@dishasolanki56
@dishasolanki56 2 жыл бұрын
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.
@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 Жыл бұрын
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 ?
@m_forever7
@m_forever7 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 2 жыл бұрын
@Meenakshi - I've added a link to the description with the SQL code to create the tables. Hope that helps!
@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.
@Modi_In_Canada
@Modi_In_Canada Жыл бұрын
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.
@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.
@trupti6251
@trupti6251 Жыл бұрын
Is it correct if we have a status in fine_payment which will contain whether the payment is due or paid ?
@DatabaseStar
@DatabaseStar Жыл бұрын
Yes that can work
@MuhammadHuzaifaKhan-o3s
@MuhammadHuzaifaKhan-o3s 11 ай бұрын
How do I know that which fines are pending for the specific member?
@DatabaseStar
@DatabaseStar 11 ай бұрын
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.
@puneetyadav492
@puneetyadav492 4 ай бұрын
Thank you
@DatabaseStar
@DatabaseStar 4 ай бұрын
You're welcome
@Photonsr
@Photonsr 3 ай бұрын
Is this database normalised to 1NF, 2NF and 3NF?
@DatabaseStar
@DatabaseStar 3 ай бұрын
Yes it should be normalised to 3NF.
@rajatssphere8781
@rajatssphere8781 2 жыл бұрын
Can you provide the code for this database...only just for few tables because idk how to do that.
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Good idea Rajat, I'll add the code (as mentioned in another comment).
@DatabaseStar
@DatabaseStar 2 жыл бұрын
@Rajat - I've added a link to the description with the SQL code to create the tables. Hope that helps!
@tylercondon3453
@tylercondon3453 2 жыл бұрын
Very informative video! Thanks so much!
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Glad it was helpful!
@rhythmrhy1380
@rhythmrhy1380 Жыл бұрын
Excellent job
@DatabaseStar
@DatabaseStar Жыл бұрын
Thanks!
@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 жыл бұрын
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.
@nadaawad9828
@nadaawad9828 Жыл бұрын
Thanks 💖
@DatabaseStar
@DatabaseStar Жыл бұрын
You’re welcome!
@sahilsiddiqui3210
@sahilsiddiqui3210 Жыл бұрын
what about the librarian , library having differnt branch
@DatabaseStar
@DatabaseStar Жыл бұрын
Good ideas. Yes you can add those to this design.
@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.
@tommurd3116
@tommurd3116 Жыл бұрын
Do you have dfd for this system?
@DatabaseStar
@DatabaseStar Жыл бұрын
No not for this 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)
@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
@IrfanRafiq-os3ed
@IrfanRafiq-os3ed 4 ай бұрын
please share some queries to get data from this library database
@DatabaseStar
@DatabaseStar 4 ай бұрын
I can add some in the future.
@carthai4590
@carthai4590 4 ай бұрын
i'm a fan of yours
@DatabaseStar
@DatabaseStar 4 ай бұрын
Thanks!
@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.
@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
@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.
@hhhh11517
@hhhh11517 2 жыл бұрын
is all the ids in the diagram same.
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Yes I believe they are
@theuntrainedsinger1185
@theuntrainedsinger1185 10 ай бұрын
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 10 ай бұрын
Good point, and that is something I should have created, so we can track each copy of the book.
@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.
@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.
@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
@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 жыл бұрын
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"?
Database Design for a Hotel Management System
12:14
Database Star
Рет қаралды 14 М.
Database Design for School Students for an Entire School
18:34
Database Star
Рет қаралды 26 М.
Smart Sigma Kid #funny #sigma
00:14
CRAZY GREAPA
Рет қаралды 58 МЛН
小蚂蚁会选到什么呢!#火影忍者 #佐助 #家庭
00:47
火影忍者一家
Рет қаралды 121 МЛН
Cool Parenting Gadget Against Mosquitos! 🦟👶 #gen
00:21
TheSoul Music Family
Рет қаралды 32 МЛН
А что бы ты сделал? @LimbLossBoss
00:17
История одного вокалиста
Рет қаралды 10 МЛН
Database Design Project : Library Management System
12:09
Manish Sharma
Рет қаралды 9 М.
How to Create a Library Database in Excel
9:32
ExcelDemy
Рет қаралды 12 М.
7 Database Design Mistakes to Avoid (With Solutions)
11:29
Database Star
Рет қаралды 82 М.
Database Design Tutorial
17:10
GoSparker
Рет қаралды 956 М.
Microservices with Databases can be challenging...
20:52
Software Developer Diaries
Рет қаралды 70 М.
How to design database for a project
18:16
BBarters
Рет қаралды 95 М.
Solving one of PostgreSQL's biggest weaknesses.
17:12
Dreams of Code
Рет қаралды 205 М.
Learn Database Normalization - 1NF, 2NF, 3NF, 4NF, 5NF
28:34
Decomplexify
Рет қаралды 2 МЛН
Smart Sigma Kid #funny #sigma
00:14
CRAZY GREAPA
Рет қаралды 58 МЛН