Mapping taxonomy terms from Drupal 5 to Drupal 7

In Drupal 7 tagging terms are stored as fields of the entity. In previous Drupal versions tags are assigned to nodes stored in a table taxonomy_index(nid, tid, created). In D7 we have some table as for example field_data_field_taggings were each term refrerence is stored as a row. If more then one term is assigned to a content node (e.g. in the answers module), the value in the column delta incremented to have a unique key. To generate this table we need an sql statement that increments this delta if more than one term exist for the node.
1 answer

INSERT INTO field_data_field_taggings (entity_type, bundle, deleted, revision_id, language, delta, entity_id, field_taggings_tid)
SELECT "node" as entity_type, n.type AS bundle, 0 AS deleted, n.vid AS revision_id, "und" as language,
@i := IF(n.nid > @prev_nid, 0, @i + 1) AS delta, @prev_nid := n.nid AS entity_id,
tid as field_taggings_tid FROM taxonomy_index t, node n
JOIN (SELECT @prev_nid := NULL, @i := -1) v
WHERE n.nid=t.nid

Taggings: