Remove attachment from database

Just use a custom $wpdb query, something like

function remove_all_attachments() {
  global $wpdb;
  $ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type="attachment"");
  if ( empty($ids) ) return;
  $remove = implode(',', $ids);
  // remove post meta
  $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id IN ({$remove})");
  // remove posts
  $wpdb->query("DELETE FROM $wpdb->posts WHERE ID = IN ({$remove})");
}

After that just call remove_all_attachments() whatever you want and all your attachemnts posts are gone, but the file stay there…