Can someone copyright a SQL query?
stackoverflow.com
stackoverflow.com
The takeaway from this is to always specify that the work of a contractor is a work for hire. Otherwise they own what they produce.
I suspect in this case the contractor was a lot smarter than the school district. If so, they need to hire someone else to produce a new query from black box specifications. Another technique that works is to ask for a copyright release or threaten to go to the local press.