first working version of triggers and function sql script