Duplicate Id when adding new record

Drupal will cache the next available id for a table locally. This is not normally a problem, however when you have added data directly to the database it will throw a duplicate id. I think this caching is over kill but have not found a way of changing this behaver yet. A friend of mine had already come across this problem and sent me this SQL code which clears the cache completely.

delete from cache;
delete from cache_page;
delete from cache_filter;
delete from cache_content;
delete from cache_menu;
delete from cache_views;
delete from watchdog;