Chapter 11. Useful scripts
This chapter covers
- Viewing everyone’s last-run SQL query
- A generic performance test harness
- Estimating the finishing time of jobs
- Finding where your query really spends its time
- A simple lightweight tracing utility
Gallimaufry refers to “odds and ends,” and that nicely sums up the content of this chapter. It contains a hodgepodge of scripts that can reveal some interesting and useful information. The scripts given in this chapter wouldn’t sit comfortably within the other chapters of the book.
The content of this chapter is wide ranging, covering such diverse areas as finding which SQL queries everyone last ran, getting Windows system information within SQL Server, determining where your queries really spend their time (as opposed to the cached plan estimate), and a lightweight SQL tracing utility. We’ll begin by looking at how you can view everyone’s last-run query.
Viewing details of everyone’s last-run SQL queries can be useful in understanding how your users use the database. It can also be useful in checking users when they say, “the only SQL I ran was….” Often there’s a difference between what users say they’ve done and what they’ve really done. The script provided here should help clear up this discrepancy.