Useful SQL templates for SQL SERVER 2008 R2

Posted on 2013-01-21
Last Modified: 2013-01-24
Hi Experts,

 I come across a template for Transaction in below path. I would like to have such useful templates more. Could you please share with me if you have?

  Some of the mostly useful scripts such as given below are added as template in my SSMS. It is useful. I would like to get more such kind of scripts. If you have please do share with me.

To identify text in SPs:

select dISTINCT
FROM syscomments sc
INNER JOIN sysobjects so ON
WHERE sc.TEXT LIKE '%update%mytable%' 

Open in new window

Question by:Easwaran Paramasivam
  • 5
  • 3
  • 2
  • +1

Expert Comment

ID: 38800999
This is a pretty big open ended question. Most DBAs are likely to have a large collection of scripts in their toolkits.

SSMS has it's own set of templates which can be useful - go to view>Template Explorer or Ctrl+Alt+T

Alternatively you could ask for more specific scripts or templates and I'm sure you'll find what you need.
LVL 28

Accepted Solution

Ryan McCauley earned 250 total points
ID: 38802586
Agreed - there are more out there than I can include, but here are some links to get you started on a solid collection of management scripts:

Also, if you want to know everything there is to know about a SQL Server, it's configuration state, and potential warning signs, all in one place, check out Brent Ozar's sp_BLITZ:

Especially if you're taking over a server you've not managed before, it's critical in getting you a  snapshot of the state of things as quickly as possible.
LVL 35

Expert Comment

by:David Todd
ID: 38802761

Something I've done is to personalise those templates - add fields, default others, and add some boilerplate. That collection I put in a folder with my name.

While its great to have a big collection, there isn't anything useful about a template you don't use imho or don't understand.

LVL 28

Expert Comment

by:Ryan McCauley
ID: 38802788
Agreed - those templates are great and save time, but you have to make sure you understand what they're doing (or, at minimum, understand what the results actually mean). I've got them in a folder on my workstation that watched with Dropbox, so the most up to date copies I work with are always available whenever I need them. It took me a while as an early DBA to realize that typing the same code over and over wasn't a time-saver - it's not too long because a 15 minute task you repeat constantly is worth the 2 hours it takes to create a solid script and stow it away.

Even better when people smarter than me put the scripts together and publish them for general consumption. Soak up what you can!
LVL 16

Author Comment

by:Easwaran Paramasivam
ID: 38804263
Thanks for your valuable information. What I'm looking for as developer level. Not at DBA level. Yes, I do know microsoft already provided some templates for basic operations.
Except that as a developer we do search some table used in SP instead of using view dependency of the table (I mentioned in question itself). Like this if you perform any other kind of operation as a developer using your own templates(or refer some resources from where I could get them) please do share with me.  I know my question is not specific - means I believe that from experts I could get more useful templates which would save my time.

If you have please do share with me. Otherwise I'm happy with the information given here. I could give points!!
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

LVL 16

Author Comment

by:Easwaran Paramasivam
ID: 38804291
I could say one example. The script which clear cache.

I tested a SP with some parameters. I calculate time to execute. I run with other parameters, it would be fast as because of the cache. I would like to clear the cache at particular time. I look for script for that.

Assisted Solution

MattSQL earned 150 total points
ID: 38804296
DBCC DROPCLEANBUFFERS will clear the buffer pool
DBCC FREEPROCCACHE clears the plan cache
LVL 16

Author Comment

by:Easwaran Paramasivam
ID: 38804343
Interesting.  @MattSQL - Could you please explain what is buffer pool and what is plan cache. Difference b/w them?

Assisted Solution

MattSQL earned 150 total points
ID: 38804350
The buffer pool contains data pages that are read into memory, the plan cache contains prepared query plans that could be reused.

Clearing the buffer pool is useful when testing. For example if your query retrieves a bunch of data, after it is run the first time the data will reside in memory (in the buffer pool) and subsequent runs will be much faster.

The plan cache stores prepared query plans. Again, on the first run of a query SQL Server will pass the query to the optimiser to prepare a query plan. Subsequent runs can use the plan from the cache and hence be faster.

CAVEAT: I have simplified things a bit here - both the plan cache and buffer pool are huge topics in SQL Server....
LVL 16

Author Comment

by:Easwaran Paramasivam
ID: 38804369
Thanks. Got idea. You have any other useful snippets that could be used as templates? If so, please do share.
LVL 16

Author Comment

by:Easwaran Paramasivam
ID: 38814085
I've requested that this question be closed as follows:

Accepted answer: 0 points for EaswaranP's comment #a38804369
Assisted answer: 134 points for ryanmccauley's comment #a38802586
Assisted answer: 133 points for MattSQL's comment #a38804296
Assisted answer: 133 points for MattSQL's comment #a38804350

for the following reason:

Even I did not get more developer handy templates the given answers are informative.

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL Query Syntax Error 9 33
Log Backup 2 13
MSSQL Frequency of Years From Days Field 2 14
SQL Date Retrival 7 28
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now