RELATIONSHIPS - You can defined on a relationship, a condition when one field’s record is either updated or deleted. (I’m not positive on determining of the 2 tables, which field it’s looking at for updates/deletes in order to propagate changes to the other table.
ie. in the Posts.post_slug and Comments.post_slug example, if you put a CASCADE UPDATE on the relationship, is it watching for the Posts.post_slug to update, and then propagate changes, or is it watching the Comments.post_slug for changes?
Either way, it comes down to 2 rules: DELETE RULE and UPDATE RULE. Each can be set to one of 4 options: DO NOTHING, CASCADE (UPDATE/DELETE), SET NULL or SET DEFAULT.
The DELETE RULE happens when you DELETE the (?) record. The UPDATE RULE happens when you UPDATE the (?) record.
For NO ACTION, nothing happens. I don’t know why you’d create a relationship if nothing was going to happen, maybe you can enlighten me?
For SET NULL, the field has to support NULL values and on UPDATE/DELETE, the other table’s field is set to NULL
For SET DEFAULT, the field has to have a DEFAULT set and on UPDATE/DELETE, the other table’s field is set to its DEFAULT.
For CASCADE, when you UPDATE, the value has to be updatable (you can’t update a seeded field) and when you change the value, the other table updates as well. (Like if you updated the post_slug of a post, all comments for that post will update their post_slug to the same value) When you CASCADE and DELETE, all records referencing that first table’s field are deleted as well. (Like if you delete a post, all comments on that post get deleted too)
Special note, in order for 2 fields to be relational, they need to support the same datatype. If your Posts.post_slug is a varchar(50) and a relational field in Comments.post_slug is varchar(40), if the value set in Posts.post_slug ever exceeded 40 characters, the Comments.post_slug would not be able to properly maintain the relation.
So how am I doing so far, Rudy?