Friday, October 4, 2013

Find an index across databases

Some tools report back the name of an index without the name fo the database it's in... other folks may have an index in some of their SaaS databases, but not all. Here's one way to find them all.
 

 

declare dbs cursor for

select name from sys.databases where name not in ('master', 'tempdb', 'model', 'msdb') order by name

go

open dbs

 

declare @name varchar(1000), @string varchar(2000)

 

fetch dbs into @name

 

while @@FETCH_STATUS = 0

begin

 

fetch dbs into @name

set @string = 'select * from [' + @name +'].sys.indexes where name like ''_dta%'''

set @string = 'if exists ( ' + @string + ') begin ' + 'select '''+ @name + '''' + @string + ' end'

 

print @string

 

end
 

close DBs

 
Deallocate dbs

Tuesday, July 30, 2013

Advice for newbies

Here's a list of things I talk to new IT folks about; they are things I didn't always get right over time, or things that new folks drove me nuts doing:


1)      Accurate is more important than fast

2)      Fast is good as long as it doesn’t violate rule #1

3)      Late is occasionally going to happen; late without warning management should not happen

4)      Try new things. Life is a learning experience.

5)      Ask for help if you’re not sure you’re going to get something right. See #1

6)      Show initiative. You are also being hired for your brain. Use it.
 
7)    You don’t have the whole picture.  If you need more of the picture in order to make smart decisions, ask for it.

Monday, April 22, 2013

Wednesday, April 17, 2013

Thursday, April 4, 2013

How many rows are in your tables?

If you need counts on all of your tables (perhaps you are doing some data mining on a new server?), you probably don't want to run a "selcet count (*)" on all the tables -- it's time consuming and resoruce intensive.

Instead, try this:


SELECT sc.name +'.'+ ta.name TableName

 ,SUM(pa.rows) RowCnt

 FROM sys.tables ta

 INNER JOIN sys.partitions pa

 ON pa.OBJECT_ID = ta.OBJECT_ID

 INNER JOIN sys.schemas sc

 ON ta.schema_id = sc.schema_id

 WHERE ta.is_ms_shipped = 0 AND pa.index_id IN (1,0)

 GROUP BY sc.name,ta.name

 ORDER BY SUM(pa.rows) DESC

Friday, February 15, 2013

SQL Saturdays...

Looks like I'm going to be speaking at SQL Satuirday in Tampa in only a few weeks; then in Jacksonville a couple of months later; and possibly, in San Juan in between. (Also thinking about Manhattan in August... )

Be sure to come over & say "Hi!"

(Register here:  www.sqlsaturday.com )

Friday, December 21, 2012

performance?

A recent forum post pushed enough of my buttons that I chose to respond, and the topics themselves were interesting, so I'm copying the post here.


 

1) Science vs. Art

People frequently define tuning as an art rather than a science, but what is scientific method? You postulate a theory, test it, and repostulate if necessary. That's what we do when we tune.
 

2) What's a valid baseline?

I remember shocking a group of about 100 recent IVY grads at a talk I did a while back when I stated that business is not like a college exam; there is no "right" or "wrong," there is instead "the solution works" or "the solution doesn't work" ... there may be multiple correct (i.e. working) answers.

In this case, you need to be able to answer questions along the lines of "Are all of the potential bottlenecks on our system wide enough to accommodate the current expected usage and identified expected growth?" If the answer is yes, you're in good shape. If you're looking for harder numbers, my personal preference is not to exceed 70% of resources at normal peak demand; if you are, then you've got room for unexpected peaks; if you're above 80%, you need to tune or shop. (this is a VERY general rule and needs to be applied with knowledge of your system of course.)

If you can't answer these questions you need to reexamine your work so that you can do predictive analysis

3) Where do we start tuning?

About 6-7 years ago, after doing little but tuning for 15 years, I've changed my approach. Before interviewing users about their issues, or looking at perfmon which gives us a snapshot view of a very tight time slice, I install a tool (the one I currently use is Confio Ignite -- subjectivity warning, here, as we resell this tool, but I examined a dozen others before choosing Ignite). After the tool starts collecting, I interview the users about what they think their problems are, and subsequently start looking at what the tool is collecting, starting at a macro scale and moving from there to the micro scale based upon findings at a higher level; this may lead me to anything from disk issues to specific queries run by specific users at specific times of the day.