Please or Register to create posts and topics.

How to add Tags to the Contacts directly from the database

The following tables are used to add Tags to the Contact:

tag tag_id is the primary key, tag_group_id is the foreign key of the taggroup table
taggroup - tag_id is the foreign key of the tag table, org_id is the organization id in the groups table. For ungrouped tags the name is always hardcoded to !!
tabobject - tag_id is the foreign key of the tag table, object_type_id = 14 (for contacts) and object_id is the same as the contact_id in the contactmeta table.

Here are the steps:

  1. Find the contact_id of the contact from the contactmeta table
  2. Get the org_id from the groups table
  3. Add an entry to the taggroups table
  4. Add an entry to the tag table
  5. Get the contact_id from the contactmeta table
  6. Add entries to the tagobject table

Lets see an example:

  • Adding a tag group: insert into taggroup (org_id, name) values (1, 'My Group') -- note tag_group_id is the primary key
  • Adding a tag: insert into tag (tag_group_id, name) values (1, 'My Tag') -- note that tag_id is the primary key, also you cannot have the same tag name for two entries.
  • Adding the required tags: insert into tagobject select 1, 14, 23
Note that you can combine multiple sql statements into one using multiple insert and selects statements.
WARNING: Please take a backup copy of the database before making any direct changes, any errors during these steps may take the database to an inconsistent state which may not be recoverable.