Electrical wires are usually screwed onto the terminals of outlets and fixtures. If you pull on that wire, you could pull the electrical connection loose. That is why in household wiring, all wires coming out of junction boxes must be stapled down to the house framing within 6 inches of the box. It is also why there are clamps of some kind on all good plugs and extension cord receptacles.
When you work with the wiring in a lamp, you want to have a knot in the wiring, where it goes into the base of the lamp, to prevent pulling the wire back out. And within the socket fixture itself you should tie what is called an Underwriters knot, named for the standard establishing Underwriters Labatory. You can see that knot above or see even more details by clicking on Re-wiring a lamp.
Click here for information on the LEGALITY OF DIY ELECTRICAL WORK.