The purpose is to "increase" the route network. Once you codeshare with someone, the flights you can sell increase exponentially. Lets say you want to fly from ATL-EWR, but Delta only has like two flights (not sure what the actual number is, but just roll with me here). Through the codeshare with CAL, that number of flights increases by a bunch. Let's say CAL has like five from ATL-EWR. Now, Delta has seven flights it can sell tickets on. Different codeshare deals work different ways, though. Some limite the number of seats an airline can sell on another carrier, some are totally open. I THINK the SkyTeam one is totally open. I've seen almost entire XJT flights full of NWA ticketed passengers.
From an operational standpoint, codeshares easy the process for mx cancellations and wx delays. You have a lot more options to get your passengers from point A to point B. Same with oversells. We used to overbook the MEM-IAH flight all the time, or (like THIS ever happens) wx delays coming from EWR would back the flight up to the point where people would miss their international connections. The codeshare allowed us to tab into NWA's system, book the passengers on a NWA MEM-IAH flight, print out their new ticket and send them on their merry (well, not so merry) way.