It might be said that the Great Wall was built to as a fortification to protect Qin Shi Huang ´s dynasty. (Qin dynasty) against nomads incisions. It was built to keep nomadic tribes such as Mongol. Turic, etc.
It has always maintained as a militar defence but it has different uses, like being a transportation corridor, it was used to regulare trades and to restrict migration.