How to add Tags to the Contacts directly from the database
Quote from Deepa Kapoor on November 28, 2025, 2:18 amThe 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:
- Find the contact_id of the contact from the contactmeta table
- Get the org_id from the groups table
- Add an entry to the taggroups table
- Add an entry to the tag table
- Get the contact_id from the contactmeta table
- 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.
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:
- Find the contact_id of the contact from the contactmeta table
- Get the org_id from the groups table
- Add an entry to the taggroups table
- Add an entry to the tag table
- Get the contact_id from the contactmeta table
- 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
