June 12, 201115 yr I'm creating a document library system for a client and have nearly finished. I need a way to find documents that have had their category deleted. I know I can just loop through all of them and check if the cat_id links to a valid record but I'm hoping someone knows of a more efficent way of doing it?
June 12, 201115 yr Use an exclusion join - http://www.xaprb.com/blog/2005/09/23/how-to-write-a-sql-exclusion-join/ You really shouldn't have orphaned records in the first place though, you should enforce referential integrity using cascades - http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html
June 12, 201115 yr Does each document have one category only (ie it's set in a field in your documents table) or are there multiple categories possible (has and belongs to many relationship)? As Jock rightly says, this should never happen in a good application
June 12, 201115 yr you should enforce referential integrity using cascades I've seen a couple of hosts - don't recall which off the top of my head - who only support MyISAM. To which I'd say, change your host and then do what Jock says.
Create an account or sign in to comment