Updating database SQL and inserts