Jump to content
Larry Ullman's Book Forums

Foreign Key Constraints

Recommended Posts

Morning Larry et al,


Regarding Foreign Key constraints in the command


CONSTRAINT fk_page_user
FOREIGN KEY (user_id)
REFERENCES yii_cms.user (id)


ON DELETE - does that mean you're deleting the `user_id` of the page table (the table in which the sql command was written) or the `id` of the user table it references, or something else?


Thank you



Link to comment
Share on other sites

Good question. If you have a page record whose user_id value is 45, and the user record whose id value is 45 is deleted, the constraint dictates what is done with the page record. SET NULL would mean set that page record's user_id value to NULL.

  • Upvote 2
Link to comment
Share on other sites

  • 2 weeks later...

Good things come to those who wait. ;)


Relax, everyone. Quality will be affected if he rushes this book out. I'm sure everyone will gain on him not rushing this.


I was just winding him up, Ive been starting to mess around with Yii a little bit. And also reading the Alexander Makarov cookbook which is available. By the way Antonio there is three ways you can build queries in Yii, you can use Active Record which is the slowest, you can also use Query Builder or if you want the fatest you can use the Standard SQL(DAO) method. So with queries and Yii there is nothing to worry about, i remember you wrote about how inefficient code ignitor quiries were.

Link to comment
Share on other sites


  • Create New...