Pages

Wednesday, 15 May 2013

How many rows in that table?

How many of us have typed ‘select count(*) from TABLE’ when we want to know how many rows in a table?

There is another way, by querying sys.partitions. 

I’ve compared the performance and IO.

 
   1:  SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
   2:   
   3:  SET STATISTICS TIME ON;
   4:   
   5:  SET STATISTICS IO ON;
   6:   
   7:  SELECT COUNT(1)
   8:  FROM   MYBIGTABLE
   9:   
  10:  DECLARE @objid AS BIGINT;
  11:   
  12:  SELECT @objid = object_id
  13:  FROM   sys.tables
  14:  WHERE  name = 'MYBIGTABLE';
  15:   
  16:  SELECT SUM(rows)
  17:  FROM   sys.partitions
  18:  WHERE  index_id IN (0, 1)
  19:         AND [object_id] = @objid;
  20:   
  21:  SET STATISTICS TIME OFF;
  22:   
  23:  SET STATISTICS IO OFF;  

The results from STATISTICS IO and TIME are as follows;


Table 'MYBIGTABLE'. Scan count 1, logical reads 115328, physical reads 0, read-ahead reads 115328, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.


SQL Server Execution Times:
   CPU time = 27628 ms,  elapsed time = 61186 ms.


So over a minute.


For the query on sys.partitions;


Table 'syssingleobjrefs'. Scan count 1, logical reads 2, physical reads 2, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'sysidxstats'. Scan count 1, logical reads 2, physical reads 1, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'sysschobjs'. Scan count 1, logical reads 4, physical reads 2, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.


SQL Server Execution Times:
   CPU time = 16 ms,  elapsed time = 140 ms.


(1 row(s) affected)
Table 'sysrowsets'. Scan count 1, logical reads 10, physical reads 0, read-ahead reads 7, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.


SQL Server Execution Times:
   CPU time = 0 ms,  elapsed time = 35 ms.


So 140+35=175ms, so less than a quarter of a second compared with 61 seconds.


Much much much much much much faster!

Monday, 8 April 2013

Technology: Why I Hate and Love you so…

I word in IT, I love and hate technology with equal passion…

Technology makes our lives better, wireless networks, cheap computers, mobile phones that can make calls / play games and make a terrible cup of coffee… We can do more..cheaper.. 

But its the most frustrating thing in the world, when the iPad doesn’t find the airport printer…What do you do? Reboot everything….if that doesn’t work, setup everything from scratch again…if that doesn’t work? Pray to the God of Calculators… if that doesn’t work??? ? ? ? Hours later… still doesn’t work, even after selling my soul to the God of Calculators….

But wait a second, the iPhone can see the airport printer… so its a problem with the iPad..

At that point I give up and print from a PC {wirelessly}– several hours of my life I will never get back….

Viva technology!!

More Blogging…

This is my second post where I state my intention to blog more…’this time is personal’ (tag line from Jaws: The Revenge’ )…

Just like everyone else I have blog ideas that fade into nothingness, either I forget it and move on or it takes so long to write something witty and informative that it just gets binned…

So I will try and keep then short and sweet, amusing if possible, but unlikely. But most of all, actually blog something.

Sunday, 16 December 2012

12 days of Geekmas..on the 3rd day

Yes, I am a geek and Yes, I'll do almost anything for something geeky :-)



Tuesday, 27 November 2012

#BADSQL 2

This is my 2nd submission for bad SQL..

Bad SQL 2:
The dev system has run out of disk space.  Lets shrink all the databases, that will free up some space.

EXEC sp_MSForEachDB 'DBCC SHRINKDATABASE (''?'' , 0)'

It might seam like a good idea, but it does apply to EVERY database.
DBCC SHRINKDATABASE ('master' , 0)
DBCC SHRINKDATABASE ('tempdb' , 0)
DBCC SHRINKDATABASE ('model' , 0)
DBCC SHRINKDATABASE ('msdb' , 0)
DBCC SHRINKDATABASE ('ReportServer' , 0)
DBCC SHRINKDATABASE ('ReportServerTempDB' , 0)

Monday, 26 November 2012

SQL Event Calendar

 

The SQL event calendar for next year is filing up!!

Tell your friends/colleagues and your pets!

 

SQL Santa London (#sqlfaq) 14th December - http://sqlserverfaq.com/events/452/SQL-Santa-2012.aspx

SQL Saturday Exeter (#sqlsat194) 8th-9th March – http://www.sqlsaturday.com/194/eventhome.aspx

SQLBits XI Nottingham (#sqbits) 2nd–4th May - http://sqlbits.com/

SQL Saturday Scotland  Edinburgh (#sqlsatscotland)  7th-8th June - https://twitter.com/SQLScotland

SQL Relay – (#sqlrelay) Dates coming up…. 

SQL Server User Groups (UK Wide) Various dates (#sqlfaq) - http://sqlserverfaq.com

SQL Saturdays (World) Various dates (#sqlpass) http://sqlsaturday.com

Bad SQL, Naughty SQL!

 

During my time as a dev, I’ve done some bad things in SQL, some terrible things that still give me nightmares. 

But I feel like a bit of therapy and I should share, and perhaps you would like to share too?

Bad SQL 1:

I think I used it on a dev system that ran out of space.

   1:  EXECUTE sp_MSforeachtable "ALTER TABLE ? REBUILD WITH (DATA_COMPRESSION = page)";  

 

Feel free to share your BAD SQL, please post anonymously if you are too ashamed. Smile

Wednesday, 21 November 2012

SQLBits XI and SQL Saturday Exeter (194)

It never rains but it pours, not one but two SQL conferences for us to get our teeth into.

SQLBits is back and in the Midlands, Nottingham to be precise – the home of Robin hood… 2nd-4th May.  www.sqlbits.com

And SQL Saturday Exeter (192) is taking place on the 9th of March at Jurys Inn Hotel Exeter, Western Way, Exeter http://www.sqlsaturday.com/194/eventhome.aspx

I’ll be there! Hopefully you can be too!

Monday, 1 October 2012

Hello Proteo!

Today I took up my new role as Lead Developer/Architect at Proteo. 

They do a number of really interesting products; check out their website!

I have an idea of what I will be doing, but all will be revealed over the next few weeks.

Its going to be an exciting time. 2 weeks after I start there is an office move. I got to visit the new office today. 

IMG_20121001_133314IMG_20121001_133322

(Here are some pictures from the development floor )

Goodbye Co-operative work family

This week I’m taking up a new challenge and moving to Proteo – It’s not only a job change but a relocation up to Norwich.  Its a huge change and a big challenge, but its one I’m very much looking forward to. 

I am leaving behind my ‘work’ family, all the people I have known over the last 6 years, people I have spent 45 hours week with, through thick and thin, good times and incredibly stressful times.  But now with the *unsocial media of Facebook and twitter I can still badger them and try to get them to go to the Southampton SQL Server User Group or the Southampton NxtGen user group.

I would like the thank my close work family (the Guys and Girls in Eastleigh) but also the cousins in Manchester and Stoke.  I will miss everyone of you! 

I am also temporary leaving behind Zara, Tabitha and Matilda – but not for long, they will be following me up very very soon.

Mark

*How social can social networking be, when you do it on your own? Doesn’t that defeat the point of being social?

And Finally in the words of Peter Cook & Dudley Moore…

Goodbye… (YouTube)

“Goodbye, we wish a fond goodbye, fa-ta-ta-ta-ta, fa-ta-ta-ta”

Full Lyrics here (search for goodbye)

Thursday, 13 September 2012

SQL Sat #162–What do you get out of it?

I’ve just got back from SQL Saturday #162 Cambridge and two people have asked me “What do you get out of it?

Two things struck me;

a) How difficult it was to come up with something tangible (there are plenty of intangible reasons) – I got a helper shirt. Smile

b) The phasing of the question, the expectation of ‘getting something’.

 

So why do I do it? Why get involved?

BECAUSE I CAN and because I enjoy it.  I enjoy the satisfaction of putting on a good event, I get a kick from knowing I was part of a team that made stuff happen.

So it’s not about what you get out of it; it’s about what you put into it that matters.

 

Why Don't You Just Switch Off Your Television Set and Go and Do Something Less Boring Instead? 

Go to a local User Group?  Go to a SQL Saturday ? Go to SQLBits ?

Get involved!! The intangible benefits are huge…but that’s another blog post.

 

MPM (@tsqltidy)

Saturday, 19 May 2012

SQL Server Management Studio (SSMS) Add-in update

Its been a while, infact a very long time since I blogged about anything....blah..blah..blah

I did some work on a SSMS Add-in for Denali, and I've only just started to look at SQL Server 2012...

Guess what... Its doesn't work! I know that Add-in for SSMS are not supported, but please.. could we have it working between any two versions?!?!

This time, its an easy fix.  The folder the .addin files are being picked up from has been changed.
So instead of looking here; C:\Users\Public\Documents\microsoft\msEnvShared\Addins
Your .AddIn needs to go here instead; C:\ProgramData\Microsoft\MSEnvShared\AddIns

Very easy to fix, but a pain to find solution.