To delete a block programmatically using the Database API, try this:
$module = 'block';
$delta = 1;
// Get the block id (bid) required to delete the correct block from table 'block_custom'
$result = db_select('block', 'b')
->fields('b', array('bid'))
->condition('module', $module)
->condition('delta', $delta)
->execute();
$bid = $result->fetchField();
db_delete('block_custom')
->condition('bid', $bid)
->execute();
db_delete('block')
->condition('module', $module)
->condition('delta', $delta)
->execute();
db_delete('block_role')
->condition('module', $module)
->condition('delta', $delta)
->execute();
When creating custom blocks through the Drupal Block UI, the module name is block
and the delta
value is an integer. Be sure to use the correct delta value to delete the desired block.