Dinosaur Trouble by Dick King-Smith
Nosy, a young pterodactyl, makes friends with Banty, a young brontosaurus, despite the disapproval of their parents. When the pterodactyls save Banty from the terrible tyrannosaurus rex, the adult dinosaurs become great friends as well. Nosy comes up with a plan to reach T. rex a lesson he won't forget in a hurry - and the dinosaurs live together happily ever after.