What is the mechanism for NSAIDs leading to gastric ulcer formation? Can it also cause gastritis?

With high levels of acidity and digestive enzymes, and food movement, the stomach is an aggressive environment for the tissues lining the stomach wall. Prostaglandins mediate endogenous protective mechanisms, including (1) increased mucosal blood flow; (2) increased mucus secretion; (3) increased bicarbonate secretion; and, at high concentrations, (4) reduced acid secretion.

Non-steroidal anti-inflammatory drugs (NSAIDs) inhibit the cyclo-oxygenase (COX) enzyme. COX is involved in the production of prostanoids, including classical prostaglandins. In the stomach, COX-1 is essential for the production of the protective prostaglandins. Therefore, inhibition of COX by NSAIDs increases the risk of gastritis (the general term for conditions involving inflammation of the lining of the stomach), including gastric ulcers.