Despite recent progress in some states, millions of mental-health records remain missing from the national database that gun dealers use to run background checks on potential buyers, according to a new analysis of federal data by a coalition of U.S. mayors.

Amid growing discussion of the need for new legislation on gun control in the wake of the Sandy Hook Elementary School massacre, the gaps in mental-health records in the National Instant Criminal Background Check System compromise one of the main measures already in place...