Answer the question
In order to leave comments, you need to log in
Am I correct in understanding the essence of relational databases?
I made a blog in PHP. I used MySQL as a database
. During the development of the table, I didn’t connect it in any way, that is, when a new post is added, the post itself is added with a separate request, the number of user posts in the users table is changed with a separate request, and the post is added to the moderation table with a separate request. Removal is similar, a bunch of requests. Accordingly, there is no integrity
A couple of days ago I realized that I didn’t end up with a relational database, but I just got unrelated tables. Do I understand correctly that "for good" it is necessary that when adding a post, all subsequent actions are performed not by the backend, but directly by the database itself?
Answer the question
In order to leave comments, you need to log in
Relationships between tables are needed primarily for data integrity. For example, you can make such a connection between the table of users and their posts, so that when a user is deleted, the database automatically deletes all his posts. Or vice versa, make such a connection that you cannot delete a user if there are posts from him. That is, links can create protection that ensures that no record is accidentally deleted.
Just because you don't have relationships doesn't mean you don't have a relational database. This is determined by the database itself, not by your connections.
With the help of relationships, you will not be able to automatically update the number of records in another table when inserting or deleting a record. This must be done in the request.
update
Links also help to avoid errors, for example, by mistake it will not be possible to add a post to a non-existent category or delete a category that contains posts. I hope you understand the point.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question