please help us! thank our sponsors:

25
Tulsa TechFest 2013 | Fri, Oct 11 th , 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions! Please help us! Thank our Sponsors:

Upload: rico

Post on 05-Jan-2016

28 views

Category:

Documents


1 download

DESCRIPTION

Please help us! Thank our Sponsors:. SQL Server Scripts for your Toolbox. Chris Barba Senior Developer Analyst Cimarex. Please Be Courteous!. Session Objectives and Takeaways. Session Objective(s): Provide some scripts for your SQL Toolbox Not going to review each script line by line - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Please help us! Thank our Sponsors:

Tulsa TechFest 2013 | Fri, Oct 11th, 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions!

Please help us!Thank our Sponsors:

Page 2: Please help us! Thank our Sponsors:

Tulsa TechFest 2013 | Fri, Oct 11th, 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions!

SQL Server Scripts for your Toolbox

Chris BarbaSenior Developer AnalystCimarex

Page 3: Please help us! Thank our Sponsors:

Tulsa TechFest 2013 | Fri, Oct 11th, 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions!

Please be courteous to your fellow attendees

and

set your phones to vibrate or silent mode!

Please Be Courteous!

Page 4: Please help us! Thank our Sponsors:

Tulsa TechFest 2013 | Fri, Oct 11th, 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions!

Session Objectives and Takeaways

Session Objective(s): Provide some scripts for your SQL ToolboxNot going to review each script line by lineCould be better ways of doing some of this

Some scripts help with new development, some help with support (some help with both)You can use this scripts immediately

Unless noted you don’t need elevated permissions to run

Page 5: Please help us! Thank our Sponsors:

Tulsa TechFest 2013 | Fri, Oct 11th, 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions!

SSMS 2008 Can’t Save Table Changes

Any change that causes a table to be drop and recreated can not be made.

Microsoft recommends scripting all table changes

Here’s how to fixTools -> Options -> Designers -> Tables and Designers

Uncheck “Prevent Saving changes that require table re-creation”

WarningThis will conflict if you have Change Tracking turned off.With this option off, if you change a table all tracking changes will also be deleted.

Page 6: Please help us! Thank our Sponsors:

Tulsa TechFest 2013 | Fri, Oct 11th, 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions!

How to tell which version of SQL you’re running

The features available to you depend on the version of SQL Server you are running.Why does this matter:

Asked to develop functionality that might not be available on the DB version.People might not actually know what version they have.

Super quick and easy method:Select @@version

Page 7: Please help us! Thank our Sponsors:

Tulsa TechFest 2013 | Fri, Oct 11th, 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions!

When was the last time your database was restored

When in an environment other than production you might not know how new the data is.You can see the last time a database was restored.

Page 8: Please help us! Thank our Sponsors:

Tulsa TechFest 2013 | Fri, Oct 11th, 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions!

What SQL objects have been added/updated recently

There are times when it helps to know what db objects have been added/updated recently.

Track changes in productionKnow what changed during development

Page 9: Please help us! Thank our Sponsors:

Tulsa TechFest 2013 | Fri, Oct 11th, 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions!

Row Count of all Tables in a Database

This helps to get an idea about what’s normal in terms of the volume of data.Sometimes you need a take a row count before and after doing something

Page 10: Please help us! Thank our Sponsors:

Tulsa TechFest 2013 | Fri, Oct 11th, 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions!

Search for column names across all tables

There are times when you can’t remember what table holds a specific fieldThis script will return any tables containing the specified column name

Page 11: Please help us! Thank our Sponsors:

Tulsa TechFest 2013 | Fri, Oct 11th, 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions!

Search for string across all fields in all tables in a databaseThere are times when you have data, but

you don’t know where it is stored.This script will search every field in every database for a value.

Page 12: Please help us! Thank our Sponsors:

Tulsa TechFest 2013 | Fri, Oct 11th, 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions!

Keyword search across Stored Procedures, Functions, TriggersThere are times where you don’t know

what proc, etc. is updating your table.Also you may need to know if a string is hard coded.This script will search across all your tsql code for a specific string.

Page 13: Please help us! Thank our Sponsors:

Tulsa TechFest 2013 | Fri, Oct 11th, 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions!

Get Database information

Returns information about each database on the server.Returns information like file sizes, recovery model, etc.

Page 14: Please help us! Thank our Sponsors:

Tulsa TechFest 2013 | Fri, Oct 11th, 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions!

Loop through all tables

This is an undocumented stored procedure.

You won’t see this sp in SSMS.

Makes looping through all tables simpler

This is way easier than how I used to loop though all tables

sp_msForEachTable

Page 15: Please help us! Thank our Sponsors:

Tulsa TechFest 2013 | Fri, Oct 11th, 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions!

Loop through all databases

This is an undocumented stored procedure.Allows run statements/commands against all databases on a server

sp_msForEachDB

Page 16: Please help us! Thank our Sponsors:

Tulsa TechFest 2013 | Fri, Oct 11th, 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions!

List all triggers

I avoid triggers because I always forget they are there.This script will return all triggers on a database

Page 17: Please help us! Thank our Sponsors:

Tulsa TechFest 2013 | Fri, Oct 11th, 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions!

Get list of DB objects

List all tablesList all columnsList all default valuesList all foreign keysList all Primary keysList all stored procs (with create scripts)List all views (with create scripts)List all synonyms

Page 18: Please help us! Thank our Sponsors:

Tulsa TechFest 2013 | Fri, Oct 11th, 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions!

List all tables views procs

Just need a quick list of all tables and views in a database

EXEC sp_tables

Page 19: Please help us! Thank our Sponsors:

Tulsa TechFest 2013 | Fri, Oct 11th, 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions!

Grant exec to all stored procedures

Easy way to grant execute permissions to all stored procedures.Instead of granting per user, just add users to role.You won’t have to remember to add permissions to new stored procedures

Page 20: Please help us! Thank our Sponsors:

Tulsa TechFest 2013 | Fri, Oct 11th, 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions!

Last Nights Job Run Status

This summary script will return all the jobs that ran last night and their status (success or failure).I’ve used this script to email in the morning.

Page 21: Please help us! Thank our Sponsors:

Tulsa TechFest 2013 | Fri, Oct 11th, 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions!

Track Changes to objects in your database

This script will allow you to track when/what/who makes changes to DB objects.It creates an audit table and puts triggers on the database.

Warning:You need permissions to create a table in a database.

Page 22: Please help us! Thank our Sponsors:

Tulsa TechFest 2013 | Fri, Oct 11th, 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions!

Instead of Triggers

Override the standard actions of triggering statements

Insert, Update, DeletePerforms additional actions before the events.

Ignore parts of a batchTake alternate action if an error occurs

Page 23: Please help us! Thank our Sponsors:

Tulsa TechFest 2013 | Fri, Oct 11th, 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions!

Additional Resources

You can find all these scripts on my blog along with this presentation

http://chrisbarba.com

Email me if you have any trouble or [email protected]

Page 24: Please help us! Thank our Sponsors:

Tulsa TechFest 2013 | Fri, Oct 11th, 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions!

Please Complete An Evaluation Form

Your input is important!You can access Evaluation Forms at:

http://TulsaTechFest.com

Fill them out!

You can win additional prizes!

Like a $50 Best Buy Gift Card!!

Winner drawn – Midnight, Sun Oct 13th!

Page 25: Please help us! Thank our Sponsors:

Tulsa TechFest 2013 | Fri, Oct 11th, 2013 | OSU - Tulsa | 57+ Speakers, 19 Tracks & 78 Sessions!

Please help us!Thank our Sponsors: