I want to design a spur gear of some diameter. I want to know about the mechanical formula which is applied in SolidWorks.
If making gears for actual use (i.e. machining, NOT 3D printing), I'd highly recommend looking into the products by Camnetics: http://camnetics.com/
At a minimum, check out some of the options in the software for the design of a gear, it will give a good idea of the amount of effort and calculation that goes into the process.
They also have a spur gear on their model sample download page.
If you desire to calculate and create a gear manually, check out the Machinery's Handbook. It contains lifetimes of data on gears, threads, and most other mechanical content. The current editions are mostly aimed at CNC work, but older copies are great as they predate CNC equipment.