Added triggers and function on db