How and where to use/place database queries when a webform is submitted?
You can use hook_webform_submission_insert to insert data in custom table 

ie :

function hook_webform_submission_insert($node, $submission) {
  // Insert a record into a 3rd-party module table when a submission is added.
  db_insert('mymodule_table')
    -&gt;fields(array(
    'nid' =&gt; $node-&gt;nid, 
    'sid' =&gt; $submission-&gt;sid, 
    'foo' =&gt; 'foo_data',
  ))
    -&gt;execute();
}


As mentioned in above example you will find all submitted data in 

$submission


variable.