Library of Useful (Difficult) SQL scripts

Viewed 20341

Does anyone know where I can find a library of common but difficult (out of the ordinary) SQL script examples. I am talking about those examples you cannot find in the documentation but do need very often to accomplish tasks such as finding duplicates etc.

It would be a big time saver to have something like that handy.

EDIT: Thanks everyone, I think this is turning into a great quick reference. The more descriptive the more effective it would be, so please if you see your way open - please edit and add some descriptions of what one could find. Many thanks to those that have already done so!

11 Answers

Here are a few that I find very useful:

Some Administration stuff

Glenn Berry: Five Very Useful Index Selection Queries for SQL Server 2005

  • Find "Missing" Indexes for the entire instance of SQL Server
  • Find "Missing" Indexes for a single table
  • Examine the current index structure for a single table
  • Look at index usage for a single table
  • Look for possible bad indexes inside the entire current database
  • Drill into your workload (Bonus)

SQL Server Central: Seven Monitoring Scripts

  • Failed jobs report
  • Free space by drive
  • Disabled jobs
  • Running jobs
  • Server role members
  • Last backup date
  • SQL Log

And last, but not least this resource: SQL Server Programming Hacks - 100+ List

Sql Cookbook has a variety of interesting example, though some will undoubtedly be unsupported by your RDBMS of choice. O'Reilly also has a T-SQL Cookbook, but I've never personally read it.

Forgive me for the self-advertising, but I have posted a few on my blog (http://progblog.wordpress.com) because I'm rubbish at SQL and it's a good place to store things I know I'll need in the future :-) If anyone has anything more substantial then please post, I'm as keen as anyone to get hold of something like this!

I would guess that a copy of the "SQL Cookbook" would help too.

Related