A few centuries back one of the most important things a king must produce was an heir, a boy born from a royal marriage. This was fundamental, and in fact when a wife failed to produce a male child, in some cases the ruling king would seek a Vatican dispensation to divorce his wife in order to marry another woman of noble line to mate with. What could happen if this critical condition was not met?
The War of Succession in Spain is a good lesson.
In 1700 King Charles II, last Spanish King of the House of Hapsburg died with no direct heir to occupy the throne, since his own young grandson had died over a year before. But before giving his last breath he had named his half sister's grandson as heir to the Spanish crown, who was also in line of succession to the French throne.
Thus Phillip of Bourbon, Duke of Anjou, became Felipe V. All was not well with rest of Europe, not only had the Dutch and the English planned to divide Spain and gain her for themselves, but even worse, who would be able to stop France from gaining even more influence? This was not to be tolerated, and as a consequence a war sprung up.
In the beginning Phillip V's sovereignty was grudgingly accepted, but as the Bourbon family cut off England and the Dutch Republic from the Spanish trade, things got ugly and the theatre for War of the Spanish Succession was about to begin..
By 1702 Europe was divided into two large factions. On one side there was an alliance between France, Bourbon Spain (still on the hanging line), Bavaria and Cologne. Savoy was initially with them but later switched sides. These allies accepted Felipe V as the rightful king of Spain.
On the contending side a coalition between Austria, England, the Dutch Republic and Portugal decided to support a contestant to the Spanish Crown. Archduke Charles was crowned Carlos III in Vienna while Felipe V waged war in Italy. When he reached Barcelona Aragon, Catalonia and Valencia expressed their support.
Madrid and Zaragoza were taken, but it was no bed of roses for Carlos III, he left Madrid in 1706. During the next following years Valencia and Aragon were taken by the Bourbons, Menorca by the English. Felipe V suffered a minor setback when Louis XIV's support was temporarily withdrawn during a peace negotiation.
While the two coalitions fought for the Spanish in Spain , other battles were waged in different Spanish territories In 1702 the Spanish Netherlands were occupied by the French to allegedly protect them for Felipe V. In the meanwhile the British and the Dutch attacked either separately or jointly and were victorious in several campaigns: Blenheim (1704),Ramillies (1706), Oudenaarde (1708), Malplaquet (1709).
In Italy Lombardy was attacked by the Austrian army in 1701, their aim was to conquer Milan, a territory that belonged to Spain. A couple of years later Savoy-Piemont, a French ally, decided to switch sides. Amidst the war Felipe V was forced to return to Spain as Carlos III had arrived in the peninsula with a claim to the crown and the war of the Spanish succession got even trickier.
From 1706 onwards the Austrian troop gained victory after victory in the Spanish territories in Italy, successfully occupying Turin, Milan, Parma, Naples. In 1708, once the Duke Ferdinand Gonzaga of Mantua died, the Duchy was annexed by the Austrian troops, Sardinia was surrendered by the Spanish and the campaign for Stato dei Presidii began. In 1712 the Austrian fleet failed to take the island Elba from the Spanish.
Wars were not only messy, but also very expensive. Even though the two coalitions were still fighting by 1709, peace negotiations began, though it wouldn't be until 4 and 5 years later that the peace treaties were signed.
The Treaty of Utrecht (1813) ended the hostilities with Britain and the Dutch Republic, and Felipe V was confirmed as the king of Spain, at a price though, since he then had to renounce to the rights of the French Crown, just as several French princelings gave up the right to the Spanish throne.
At the same time, Spain's European empire was partitioned, Sicily and parts of the Duchy of Milan went to Savoy, while the Kingdom of Naples, Sardinia and most of the Duchy of Milan was relinquished to Charles VI, Holy Roman Emperor and Archduke of Austria.
Additionally Gibraltar and Menorca were ceded to Great Britain, however Felipe was allowed to keep his territories overseas. He granted the British the right to trade non Spanish slaves in the Spanish Americas for 30 years, the Assiento. And thus the War of the Spanish Succession finally ended. However the hostilities between France and Austria ended a year later when the Rastatt Treaty was signed (1714) .