It would really depend on the circumstances and the age and understanding the child has. I was spanked as a child, but I was also belted by my 1st stepfather from the age of 8, so I know there is a huge difference between the two. Everyone is different and every child is different.
When I was 5 years old mum and I went to visit her boyfriends mother. I went down for a nap, but of course didn't nap. I saw a box of matches on the table next to the bed I was suppose to be sleeping on. I'd only ever seen matches used in lighting BBQ's at that stage so whenever I saw the match light, the flame always extinguished. So I'm in the bed lighting these matches and throwing them around the room. As you imagine, eventually the room is set on fire. Mum grabbed me out of the room and took me outside and spanked me, while the fire was being put out. From that time on I didn't play with matches. Not because of what had happened, but because if I did I would get a smack. Fire equals pain. Of course she could have sat me down and explained why what I did was bad. But that would not make a 5 year old fully understand the real danger in what they had done. She could have left me in the room so I could feel the pain of the fire and risk scarring me for life, or (as she did) spank me so I will equate fire with pain, without actually having to endure the pain of fire. For me, I think she was very justified in spanking me for that. Children aren't adults, their brains are not fully developed and let's face it, kids learn the consequences of things through experience and whether something brings pleasure or pain.
When a child equates pain with something, they will usually avoid it in the future. Unfortunately alot of people go to the extreme and do it unnecessarily.