Refactored AQueryWriter and changed ON-UPDATE-NULL to ON-UPDATE-CASCADE for dependent fks.