Special weapons and tactics (SWAT) teams are generally called in for law enforcement situations where military-type training is needed. This would usually include situations where police know in advance that there is a great likelihood of heavy gun violence erupting. SWAT teams are also sometimes used to deal with riots or other extreme protest situations, and they were partly created specifically for this purpose.
Regular police officers are trained to deal with dangerous situations. They generally have a good amount of training in how to use their firearms in self-defense, and they know how to restrain suspects when making an arrest. Even so, there are situations where this kind of training might not be enough. In those situations, SWAT teams might be called in.
One good example of a situation where SWAT teams might be utilized would be a bank robbery. Most bank robberies happen while there are customers in the bank, and it's very common for a hostage situation to develop. A bank robber is often highly volatile, and the possibility of extreme gun violence developing is very real. There is also a big possibility that innocent people could be caught in the middle of a gunfight between the cops and robbers. SWAT teams are trained to deal with these situations while minimizing the risk of casualties among the hostages.
Law enforcement invented SWAT during the 1960s and 1970s, primarily to help deal with riots among those protesting for equal rights and against the Vietnam war. Police realized that large numbers of people were impossible to control, and sometimes situations could develop that might require very special training. Over time, SWAT teams have come to be used much more often for situations involving potential gun violence, partly because riots are generally quite rare.
One of the main differences between SWAT teams and regular law enforcement officers is the kinds of weapons they often carry. For example, these teams often use sub-machine guns, assault rifles, and shotguns. They also usually wear heavier body armor than regular duty officers. SWAT officers are trained with this equipment in much the same way an elite special forces soldier would be trained, usually with a special focus on dealing with gun battles in confined spaces, and sometimes with more emphasis on restraint than would be typical for the military.
The people who join SWAT teams generally have a background as regular police officers. In fact, in many areas, SWAT officers function as regular patrolmen during most of their working hours, especially in smaller police districts where dangerous situations are rare. In those cases, they would only gear up for operations during emergencies.