SQLite: Foreign KEY table constraint
Link: https://www.meetgor.com/sqlog/sqlite-foreign-key-table-constraint
Context
Source: techstructive-weekly-60
Link: https://www.meetgor.com/sqlog/sqlite-foreign-key-table-constraint
Source: techstructive-weekly-60
Link: https://www.meetgor.com/sqlog/sqlite-many-to-many-relations
Source: techstructive-weekly-60
Link: https://www.meetgor.com/sqlog/sqlite-one-to-many-foreign-key
Source: techstructive-weekly-60
Link: https://www.meetgor.com/sqlog/sqlite-one-to-one-relations
Source: techstructive-weekly-60
Link: https://www.meetgor.com/sqlog/sqlite-primary-key-column-constraint
Source: techstructive-weekly-60
Link: https://www.meetgor.com/sqlog/sqlite-primary-key-table-constraint
Source: techstructive-weekly-60
Link: https://www.meetgor.com/sqlog/sqlite-self-join-relations
Source: techstructive-weekly-60
Another great week, consistently learning SQL, developing another streak for solving problems on FreeCodeCamp with Javascript and Python, reading instead of doomscrolling.
We have seen one-to-many relationship and also the self-join relationship.
Let’s extend it with many-to-many relationship. Here one row can refer to many other rows, but that other row can also be referred by multiple rows.
That was confusing, let’s take the simple example of users and posts as usual.
One-To-Many relation, one post can only be written by one user. However, one user can author multiple posts.Many-To-Many relation, one user can author multiple posts and one post can be written by multiple users.That is the distinction, it is not about the relation, it is more about the design that your system needs.
In the last post, we had defined a one-to-many relation between the users table and the posts table.
Now, let’s create a single table where we can define a one-to-many relationship. Yes, within a single table we can reference the primary key and it can act like a link. Since it isn’t really about the table, it’s more about the row relation form each other, we an connect any rows.