Sheriff was a title, most commonly associated with the Ancient West of Earth history or the legal system of England, and used to designate a law enforcement official. In the Ancient West, sheriffs were empowered with the ability to arrest individuals for breaking the law and deputize individuals to assist them in this role.
In 1881, Johnny Behan was the deputy sheriff of Tombstone, Arizona at the time of the OK Corral shootout. In 2268 a recreation of Behan was constructed by the Melkot to executive members of a landing party from the USS Enterprise. (TOS: "Spectre of the Gun")
In 2153, the highly-bigoted MacReady and Bennings were sheriff and deputy sheriff of a Human community that had been transplanted to a planet in the Delphic Expanse by the Skagaran in 1864. (ENT: "North Star")
In 2367, in an attempt to teach Jean-Luc Picard the true meaning of love, Q transported the senior staff of the USS Enterprise-D into a recreation of Sherwood Forest and the story of Robin Hood. Q cast himself as the High Sheriff of Nottingham. (TNG: "Qpid")
In 2369, Worf attempted to bond with his son Alexander by playing the Deadwood holodeck program, in which Worf was a sheriff of the Ancient West, and Alexander his deputy. A computer malfunction caused characters in the program to begin to take on traits of Lieutenant Commander Data, however, the error was resolved. (TNG: "A Fistful of Datas")