database sql and category validation function