In theory, everything with a motor or sails that goes on the water has to be registered. Again, in theory, if you have residence qualifications in Spain, you must, by law, register your boat in Spain. In order to do so, apart from the registration fees, which depend on the size of the boat, the owner is required to pay a 14% tax on the value of the boat - which explains why a lot of owners get round the law by registering their craft in a company name. This is perfectly legal, in the same way that tax avoidance is legal but tax evasion is not.
The Spanish authorities also insist that, if a boat has an onboard tender, that must be registered separately, whereas other countries consider the smaller craft to be an integral part of the whole and do not require separate payment.
If the owner has a permanent, legal, address in his/her country of origin, the simplest method of registration is to do it in that country. But the address must be legal - you cannot use a relative's address and claim it as your own. Any owner can, naturally, set up an offshore company in any of the tax havens which proliferate throughout the world. For foreigners resident in Andalucia, the obvious choice is Gibraltar, where there is a number of specialist companies who can facilitate all the paperwork and ensure that the legal avenues are properly followed.