Saffie Roussos, 8, was one of 22 people killed at an Ariana Grande concert at the Manchester Arena on 22 May.
Author and comedian Walliams thanked Tarleton Community Primary School, in Lancashire, for the "warm welcome".
The school said he "popped in to cheer us up" by reading extracts from one of his books with "incredibly funny voices".
Walliams also handed out books to each child during the school visit on Wednesday.
Parents took to Facebook to praise him for the "amazing" and "great thing" he did for the pupils.
Susan Jackson wrote: "What a lovely, kind hearted thing to do, amazing David Williams."
Ceri Davies said it was "just what the children need, that's a lovely deserved treat for them".
David Walliams has paid a surprise visit to the school of the youngest victim of the Manchester attack.