SQL Snippets

Before performing destructive operations, it is recommended you create a database backup.

When deleting data, you can replace DELETE with SELECT to view what is about to get deleted.

Deleting All Records

-- Record values
delete from compose_record_value;

-- Records
delete from compose_record;

Deleting All Records of a Namespace

-- Record values
delete from compose_record_value where record_id in (select id from compose_record where rel_namespace = {NAMESPACE_ID} AND module_id = {MODULE_ID});

-- Records
delete from compose_record where rel_namespace = {NAMESPACE_ID};

Deleting All Records of a Module

-- Record values
delete from compose_record_value where record_id in (select id from compose_record where rel_namespace = {NAMESPACE_ID} AND module_id = {MODULE_ID});

-- Records
delete from compose_record where rel_namespace = {NAMESPACE_ID} AND module_id = {MODULE_ID};

Deleting Specific Record Values

delete from compose_record_value where name = {FIELD_NAME} AND record_id in (select id from compose_record where rel_namespace = {NAMESPACE_ID} AND module_id = {MODULE_ID});

Deleting All Soft Deleted Records

-- Record values
delete from compose_record_value where record_id in (select id from compose_record where rel_namespace = {NAMESPACE_ID} AND module_id = {MODULE_ID} and deleted_at IS NOT NULL);

-- Records
delete from compose_record where rel_namespace = {NAMESPACE_ID} AND module_id = {MODULE_ID} and deleted_at IS NOT NULL;