create query and constraints