How To: Delete corruption/orphaned records from the content databases

Orphaned records can cause a lot of trouble. The content databses should be inspected on a periodic basis to check for orphaned records.

The following STSADM command may be used to check for corruption,-

stsadm -o databaserepair -url {https://servername} -databasename {DBname}

The results of the above operation will display the list of all orphaned records. The same command may be executed with an addtional parameter to delete the orphaned records,-

stsadm -o databaserepair -url {https://servername} -databasename {DBname} -deletecorruption

Note:-
Sometimes the Configuration DB can contain orphaned records especially for the list of sites associated with a content DB. A simple detach and attach of the Content DB (using the deletecontentDB/addcontentDB STSADM commands) will help in deleting those orphaned records as well.

Update!!
Just came across another interesting blog,- SharePoint Orphans Explained