SQL for tables and table data added to txt file