We study the deformation quantisation (Moyal quantisation) of general
constrained Hamiltonian systems. It is shown how second class constraints can
be turned into first class quantum constraints. This is illustrated by the O(N)
non-linear $\sigma$-model. Some new light is also shed on the Dirac bracket.
Furthermore, it is shown how classical constraints not in involution with the
classical Hamiltonian, can be turned into quantum constraints {\em in}
involution with respect to the Hamiltonian. Conditions on the existence of
anomalies are also derived, and it is shown how some kinds of anomalies can be
removed. The equations defining the set of physical states are also given. It
turns out that the deformation quantisation of pure Yang-Mills theory is
straightforward whereas gravity is anomalous. A formal solution to the
Yang-Mills quantum constraints is found. In the \small{ADM} formalism of
gravity the anomaly is very complicated and the equations picking out physical
states become infinite order functional differential equations, whereas the
Ashtekar variables remedy both of these problems -- the anomaly becoming simply
a central extension (Schwinger term) and the equations for physical states
become finite order. We finally elaborate on the underlying geometrical
structure and show the method to be compatible with BRST methods.