Digging is often used as a means of escape. Your dog may want to leave a fenced yard because there are so many more interesting things to do elsewhere. If you don't plan to breed your dog a good way to prevent digging for this reason is to neuter him or spay her. Since deeper layers of soil tend to be cooler, your dog may be digging to find relief from the heat. Always provide a cool, shady place for your dog to rest when he's outside.
Dogs are great savers.
If you use bone or blood meal to fertilize your garden, the scent may be irresistible. Any dog may dig to excavate a den. A female dog may dig in order to provide a nest for babies, whether she is pregnant or not. The trick to stopping any pet's unwanted behavior is understanding it and then manipulating it into a behavior of which we approve. There are obvious things you can do to prevent digging, some of which are mentioned above.