I’d go for solution posted by @butlerblog – it’s a lot easier to manage and change in the future and it’s better WP practice.
But… If you’re asking… Here are the ways you can do this:
1. WP way:
function prepend_content_to_posts() {
$to_prepend = 'This will be prepended';
$posts = get_posts( array( 'posts_per_page' => -1 ) );
foreach ( $posts as $post ) {
wp_update_post( array(
'ID' => $post->ID,
'post_content' => $to_prepend . $post->post_content
) );
}
}
Then you’ll have to call that function. Be careful not to call it twice – it will add your content twice in such case.
2. MySQL way:
UPDATE wp_posts
SET post_content = CONCAT('<YOUR STRING TO PREPEND>', post_content)
WHERE post_type="post" AND post_status="publish"
Be careful to change table prefix according to your config.