skip to the main content area of this page
Search Script Archive 
Transact SQL scripts written by
DBAs and Developers for
DBAs and Developers.
If you would like to submit a script to our site click here

Get Performance Tips Directly From SQL Server
Submitted By: 2008DBA
Submitted On: 8/26/2009
Description: This script was written by Ian Stirk. You can read the full article here: This scripts makes use of Dynamic Management Views (DMVs) and Dynamic Management Functions (DMFs), so can be used by SQL Server 2005 or greater. The script allows you to inspect cached plans and extract information that can be useful in improving the performance of your SQL. read more...

Identifying Queries Running Slower Than Normal
Submitted By: 2008DBA
Submitted On: 8/26/2009
Description: This script was written by Ian Stirk. You can read the full article here: The utility described in this script allows you to quickly identify which queries are running slower than expected on SQL Server 2005. Recognising these queries will allow you to take corrective targeted action to improve their performance. Various possible solutions are proposed. read more...

Drop and Recreate Foreign Keys
Submitted By: 2008DBA
Submitted On: 7/9/2009
Description: Identifying all the foreign key relationships that exist on a table can be easily accomplished using sys.foreign_keys. However, dropping the foreign keys and adding them back can be difficult if a script does not exist. This result of this script is a list of ALTER TABLE scripts that Drops all existing Foreign Keys on a table and Re-Creates those keys that were dropped. Replace the TABLENAME and SCHEMANAME with your values. read more...

Generate Database Role Permissions
Submitted By: 2008DBA
Submitted On: 10/2/2008
Description: This script will generate a list of all users and their corresponding database role(s). As an added bonus it provides a T-SQL Script that can be executed on the database. This can be useful when you want to replicate permissions from one server to another for a given database. read more...

clear out DTA indexes and statistics
Submitted By: w
Submitted On: 4/29/2008
Description: When the Database Tuning Advisor fails or is aborted for whatever reason, it can leave behind its hypothetical indexes and stats. This script will remove these active indexes and stats from your database. Uses the is_hypothetical flag to find indexes. Uses the _dta prefix to find stats. This assumes that when you implement DTA-recommended stats, you change their name. If you have implemented DTA-recommneded stats and not changed their name, this script will remove those too. read more...

DISCLAIMER: shall not be held responsible for any damages sustained from the use of any information provided on this site.