sql - Does defining foreign keys and table relationships have any effect on writing queries? -


i putting table in mysql workbench , defining many-to-one relationships , keys foreign keys etc, , know put in actual create script. i'm wondering, make sure data model logical behind scenes point of view, or can relationships used in queries @ all? if can be, operations involve them? (brief example code wonderful)

i'm building sqlite database in sqlitemanager firefox plugin. has no options define these things, , i'm wondering if should care. (i've done pretty straightforward queries point).

in reality, can create join between 2 tables columns. whole reason of having primary , foreign keys enforce relationship between 2 tables. in word, in order add row in child table, need have parent table's primary key serve foreign key in child table. otherwise, insertion fail.

another reason using foreign key allow parent table perform cascade delete. way, don't have manually delete rows child table first, delete parent table.... if have cascade delete set properly, can delete table row , children rows gone too.

that said, if don't want explicitly define particular column foreign key, can still perform query without problems, makes er diagram difficult read coworkers because relationship between 2 tables aren't explicitly defined.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -