Return inserted serial from drupal_write_record
drupal_write_record() populates the serial field of an object you pass to it automatically. So assuming you have a serial field in your table called id, if you run code like the following:

$record = new stdClass;
$record-&gt;title = 'Title';
$record-&gt;some_other_field = 'Something';

drupal_write_record('table_name', $record);


the $record object will be auto-populated with a member representing the serial column when the function returns. In this example you can access it with $record-&gt;id.