SQL - find in one table where not in other - then create relationship


2006-05-01 Digg! icurtain Delcious icurtain
  1. SELECT btype_ind 
  2. FROM blog_prop AS bip 
  3. WHERE NOT 
  4. EXISTS ( 
  5.  
  6. SELECT btype_id 
  7. FROM blog_type AS bit 
  8. WHERE bit.btype_id = bip.btype_id 
  9. LIMIT 0 , 30  
  10.  
  11. ALTER TABLE blog_prop 
  12. ADD CONSTRAINT blog_type_link 
  13. FOREIGN KEY (btype_id) 
  14. REFERENCES blog_type(btype_id) 
  15. ON UPDATE CASCADE ON DELETE RESTRICT