To keep your spaghetti noodles or pasta from sticking while cooking them you should get the water boiling first and then once the water is boiling you can add the spaghetti noodles to the water.
Be sure to stir the spaghetti noodles constantly to avoid them sticking because if you do not stir the spaghetti noodles constantly or enough the noodles will begin sticking.
As long as you stir the spaghetti noodles constantly they should not stick but you can also add some olive oil to the water you're cooking the spaghetti in which also helps prevent noodles from sticking.
However if you do put olive oil in the water when cooking the spaghetti it might not taste as good if you add spaghetti sauce.
But as long as you're stirring the spaghetti constantly and keep the heat low on the stove the spaghetti should not stick.