Surgery is a medical procedure used to diagnose, treat, or prevent a disease or injury. A doctor recommends surgery when medicines or non-surgical treatments are not effective, or when surgery provides the best chance for recovery and long-term health.