what are the important reasons to not query sharepoint production databases , if we want to run even select sql queries is any issue to database? in a case if i want to do select query and want to know how many number of rows in alldocs table how can i know?
The issue is it is generally not supported. Your queries can introduce locks of various sorts, which may prevent something SharePoint is attempting to do succeed. So while reading is highly discouraged (and writing is outright not supported), if you must, for some reason query directly where the SharePoint OM doesn't fit, always use
(NoLock). It doesn't totally prevent locks, but it is better than not using it.
Unsupported by MS.
Direct modification of the SharePoint database or its data is not recommended because it puts the environment in an unsupported state. If a server component requires information from the database, it must get that data by using the appropriate items in the SharePoint object model, and not by trying to get the items from the data structures in the database through some query mechanism.
It is not good practice. And normally you do not need it.