This usually occurs as a result of fatigue, overuse, or improper use of a muscle. Strains can happen in any muscle, but they're most common in your lower back, neck, shoulder, and hamstring, which is the muscle behind your thigh. These strains can cause pain and may limit movement within the affected muscle group.
In many cases, however, the cause isn't known. Although most muscle cramps are harmless, some may be related to an underlying medical condition, such as:
Factors that might increase your risk of muscle cramps include:
Muscle cramps can be prevented through the following ways:
See here for reference.