Sql checks and repairs