Why was the Great Wall of China built?

Why was the Great Wall of China built?