You will need to take a look at the image_send_to_editor
filter.
This will not update existing records but it if you get it working it will apply to each newly inserted image.
very basic filter:
function give_linked_images_class($html, $id, $caption, $title, $align, $url, $size, $alt="" ){
$html; //contains the string you need to edit, you might want to consider to rebuild the complete string.
return $html;
}
add_filter('image_send_to_editor','give_linked_images_class',10,8);