SQL Saturday Louisville 2012 Pre Cons – An organizational perspective

We had our fifth sql saturday at Louisville – this time at a much bigger location, the school of business at University of Louisville. We also had a day of pre cons (our first pre con was by Kevin Kline last year, and was moderately successful with an attendance of 23 people. This year we tried 4 pre cons – we were unsure of which subject area to pick mainly, and all the 4 speakers were rated highly previously and among our loyalists). Some of the lessons learnt on the pre cons are as below:

1 The day started with a bit of confusion – one of the speakers had to move their room from what was originally scheduled since there was a class going on. We were relieved to be given an alternative.But much to our dismay this happened one more time, in the afternoon, actually disrupting an ongoing class. We learnt later that the reason was that the school actually has classes, and many happen without schedule. They helped us out greatly the next day by posting notices on doors that our classes cannot be interrupted. We also learnt not to host classes on premises that have their own events going on, particularly on working days.

2 We didn’t have the room number printed on the ticket – this was a gotcha on our part while setting up the ticketing with Eventbrite. Several attendees turned up without reading the email info on pre cons and those of us at the reception didn’t have them on us although our signboards had them. Our lesson was to keep room numbers printed on tickets going forward.

3 Some candidates walked to their rooms directly without checking in. (We assumed they would register/check in). Although we did not find anyone attending without payment – this indicated a possibility of that happening – lesson is to keep the check in process directly outside the room instead of in a common spot.

4 We learnt later from pre con speakers as well as other sql saturday organizers that having 20 attendees is generally considered good for pre cons – and we did nearly touch that number with 3 of them. The lesson to take away is possibly that two pre cons are the best way to go for us – possibly one on BI and one on the DBA track. That might give an above-average count of people for each class and also ease manageability issues.

5 One of the pre cons had an offer for multiple attendees to attend for the price of two. Initially it seemed like it sold well and brought in a few numbers, but many of those who signed up on this deal simply did not show up. Perhaps they did not get the day off or perhaps they thought it was not worth their time – we had to give away the extra lunches we bought for these people. The lesson here is to reduce ‘deals’ since there does not seem to be accountability with no payment.

All that said,  most attendees seemed very happy with what they learnt and wanted to do this again. The teachers seemed happy too since the attendance was well above average. Overall, we would call this event a success and hope to do it again, incorporating the lessons learnt. Our thanks to our teachers – Kevin Kline, Eddie Wuerch, Bill Pearson and Dave Fackler, and to all the students who attended. We don’t have a spot yet to upload their presentations but will email attendees with them – you may also want to follow their blogs for the downloads.

Becoming a DBA

This is in response to John Sansom’s call for posts describing a DBA story. Here is mine –
1 How did you get started?
I was working as a Visual Basic programmer in a leading financial company on Wall Street in the 90s. Despite being a large company with sensitive data they did not have a dedicated DBA – my boss managed a team of developers and did most of the DBA work himself. He was often overwhelmed with many things to do. I offered to learn some of his work, particularly DBA work since databases interested me. He taught me basic dba tasks – how to do backup/restore, how to create and maintain databases and certain other things that were specific to that business. He greatly appreciated my help despite having a lot to do myself. The story went well with both of us helping each other. One day it so happened that he was working late. The company had requirements for people to work late during monthly closes and it was one such night. He decided to go for a walk to give himself a break and walked into a bar. He got back in after a drink too many and dropped a mission critical database, bringing all the activities in the company to a standstill. Those were days when we did not have capabilities to log in remotely or even cell phones – so the phone in my home rang at 2 am. I was asked to get in to work immediately as it was an emergency. When I went in I learnt the story and also that he had been fired. I was able to restore the database and apply the logs. They had only lost 15 minutes worth of data and they were happy. With that came the keys of my first DBA job, and I have not looked back since.

2 Describe what a typical day is for you?
I currently work as a senior DBA in a leading healthcare company. I manage about 150 servers, with a team of 3 other DBAs. A typical day begins with a quick scan of our ticket queue – there may be tickets for failed jobs, backup failures, space issues or login problems. Sometimes these are small issues fixed easily, sometimes they may take longer depending on nature or complexity. Most of our alerting system and ticketing system is automated eliminating the need for checking individual servers since we have many. Following that is checking the queue for change management requests. These may be requests for backups, restores, promotions and the like. Most promotions involve code reviews for standards compliance and also performance – like usage of hints, appropriate indexes and so on. This may take a few minutes or a whole day depending on size of the request. Then there may be meetings to attend – a new application to be rolled out, a server upgrade to a newer version, a standards revision and so on. There may be documentation and internal team discussions on new features of SQL 2012, patches and service packs, scheduling off hour work and so on. In short, rarely a dull moment and lots of opportunities to learn and grow.

3 What advice would you give to someone considering becoming a DBA/DB Developer?
It is probably the same advice I would give to anyone who wants to be good at what they do. Brent Ozar said it very well in a post on time management sometime ago – ‘Decide you want to be incredible’. I have worked in many jobs and most of the time I would look to my collegues and friends to be as motivated as I was. Many people just want a job – they will go to a training if their boss sent them, browse the internet most of the time there too, do their jobs on a purely task basis, go home on friday, return monday, take the yearly vacation and go on again. I got a lot of attitude and a lot of ‘looks’ from people when I got excited about the latest release of SQL Server or the latest great book out there or even if I stayed late trying to fix a query to run faster. It took me a while to get it that if I had to excel it was time to ignore all that and do what is right for *me*. Passion is nothing to be ashamed of, and if you feel a passion for what you do – grow it and find places that will support it. Grow out of the need to be like ‘them’ and you will find more people like you who will inspire and motivate you to be better.

TSQL Tuesday #31: Logging: Case of the Missing LSN

 This is in response to Aaron Nelson’s call for T SQL Tuesday – on the subject of Logging. There are many things that come to a DBA’s mind while talking of logging. For this I chose an incident that happened some years ago. I had joined a new job, and the dba who had taken my spot had been there for several years before she left. She had set up most of the maintenence jobs on existing servers, most of which were on SQL Server 2000 then.

On the second day of my job I was asked to restore a backup as of a certain date/time to a development server to recover some data for an application manager. I was directed to the place where backups were stored. I found the full backup, and hourly transaction logs following that. As I set about restoring, I got a certain log that gave me a missing LSN error. The log job was set to run hourly, and the timestamps showed all logs were there and there were no errors on the job. I looked further to see if anything else was going on at that time when the log was backed up – I found a reindexing job in which the recovery model was being set to simple and back to full again. In 2005 and above if this change is done – the log chain is broken and one gets an error that a full backup is needed before restarting it. But in 2000 there was no such thing. The log chain was still broken but the job was not throwing any errors to show that. The backups were just not usable.
The process had been in place for more than 4 years, and luckily there had been no requirements to use the transaction log backups during this time interval. They even had a testing mechanism for testing backups, but they did not test backups during this particular sequence of operations. After that episode I also changed the testing process to work through job cycle – through all jobs and maintenence windows, in case there was any issue. It was a great lesson for me on backup testing and how many issues can remain dormant for years until one gets them accidentally. Luckily it was not a crisis situation when it was discovered but it might very well have been. Test your backups, and through jobs and processes as necssary, not just during small windows.

SQL Cruise Alaska 2012

I had the good fortune of joining the SQLCruise this year. Below is summary of my experience. I plan to write more detailed posts since there is so much I learnt both personally and professionally, but just had to get this out soon.

Countdown: I landed in Seattle on Thursday, May 24th. In the evening I did a tour of Seattle underground – during this tour got acquainted with fellow cruiser Wayne Sheffield and his family (wife,mom and m-in-law). They were great company on the tour and also in the days that followed. On Friday I did a tour of Snoqualmie falls – which included a visit to two wineries and a chocolate factory.The day ended with SQL Cruise kick off party – which was great fun and organized very well by Tim and Amy Ford. There was food for every taste and lots of fun games/prizes too. I picked up a few of Red Gate swag books for the user group and myself (thank you Red Gate). I left the party early since the next day seemed busy and was still suffering east coast jet lag.
Day 1: I took a cab to the pier around 11 am. The cruiseline promptly took over the luggage and I joined a big crowd of people waiting in the building outside the ship. I met with several fellow cruisers there and the wait was not long before we were called to check in. The check in process was simple – only involved a brief overview of passport and cruise documents, and one was issued tickets and other necessary stuff. By noon we were allowed to board the ship although our rooms were not ready. We were also allowed to eat lunch. It was an awesome first lunch on the sunny deck overlooking seattle harbor with a light breeze blowing in, with several friends for company. The ship took off by around 4 pm – and we were allowed to get into our rooms at the same time. After a short nap/rest everyone was ready to go for the Red Gate discover the ship contest – a fun game where we get a list of things ‘to do’ on board the ship that helped us explore various areas as well as get to know our partners well. I was paired with Jes Borland and her husband Justin – we had a great time getting around the ship and talking to various people for taking pictures with them. Jes is a natural extrovert and just being around her made me feel very upbeat, not to mention the fun we had going around various areas of the ship. By the time the contest was done we were tired – although we did not win the prize it was designed really well and thoroughly enjoyed it. The next day seemed packed with training so retired early.
Day 2: The day started with Brent Ozar‘s presentation on Procedure Cache BI. This is an area I work with a lot – I greatly enjoyed the presentation and discussion that followed. After lunch we continued with Kevin Kline‘s presentation on Leadership Skills for IT Professional. I learnt many things from this, also re confirmed my own assessment of myself – that I would probably do well as a technical expert than a manager. The class was also very interactive and we discussed lots of different scenarios ranging from outsourcing problems to difficult bosses.Kevin also mentioned the Quest give away of a whole suite of tools to all sql cruise attendees  – since I use almost all their products I asked if I could raffle this away at my upcoming SQL Saturday. I think very highly of Quest tools and this is a great give away.  In all this was a great and very enjoyable day. 
Day 3: We landed at Ketchikan bright and early at 7 am. I took a boat tour of Misty Fjords, which lasted 3 hours. The boat went through some amazing landscapes with misty cliffs and silvery waterfalls all around. We also saw some seals, eagles and bears en route (too far away for my little point and shoot camera to capture :(. After lunch we had a session with Allen White on SQL Sentry’s Plan Explorer – an excellent free tool that am already using. Allen showed many scenarios that the tool can be used with which I was not aware of. That was followed by Jeremiah Peschka‘s presentation on Killer Techniques for Database Performance. I was particularly struck by a difference he found between developer and enterprise editions on handling indexed views, and also by the ‘goats in the tree’ funny calender which I plan to order soon :)) Jeremiah also explained of how benchmarking can be doctored for any environment. I have always found his presentations to be funny and informative and this was no exception. The day ended with a fun dinner with several other sql cruise-ers.
Day 4: This day began with 3 glacier helicopter tour at Juneau. Standing on top of a glacier, the ponds of blue ice and the amazing serenity are highlights of my trip and sights i will cherish for a very long time. We spent the afternoon in the suite rented by the BrentOzarPLF team. The views from the suite was amazing. We had a story telling contest where many participants shared their stories of memorable work experiences – Darcy Williams won a Kindle fire prize for her simple,down to earth story.  Brent made mention of every one of our stories and gave each of us a gift that seemed to tie in with our stories in some way. He also took time to do a brief intro summary of his rather famous pre con professional workshop, which seemed informative in itself. That afternoon was great community time teamed up with amazing scenery as the ship sailed through the glacier.
Day 4: We docked at Skagway in the morning. I could not do the hike i had planned earlier due to some minor health issues – but the cruise line kindly accomodated me on a train ride to White Pass in the afternoon. The morning was spent shopping at the amazing art stores in downtown Skagway. The train ride was the best I had ever had in terms of scenic beauty, have a hard time even describing how awesome it was. The skagway break was long and we did not have any class this day.
Day 5: After 4 days of sight seeing this was a day of hard core training and began with Allen White‘s Introduction to Powershell. As someone who has not used much of powershell I learnt a lot from this. Allen also provided several useful links/info on blogs and books for those wanting to learn more on the subject. This was followed by Kendra Little‘s presentation on Sports Medicine for High Transaction Databases – she talked of baselining strategies for busy databases, how to find windows to do maintenence, and several other tips and tricks. The day ended with Robert Davis‘s presentation on backup and recovery strategies.
Day 6: The last day began with Brent Ozar’s presentation on Scaling SQL with Solid State. It was packed with great information on Solid State/Hard drive layout and various strategies to get the best out of it. It was a tough subject for me and i cannot claim I understood all of it but it seemed like a great start to learn more and plan to revisit these slides again soon. The training concluded with Idera Iditarod challenge – a clue based ship search with some sql questions thrown in. I was partnered with Max Gomeniouk. Max was an extremly  agile creative person who handled the ship search swiftly and well, while I fielded the sql questions. Between us we made a good team and managed to win the prize – a Kindle fire, a great start to my ebook reading habit. Thank you Idera for the well designed contest and the wonderful prize!! The afternoon was spent at Victoria, Canada –  I had dinner again with Kevin and his lovely mom Shirley and bid good bye to them.

In conclusion – you can perhaps count the number of times the word ‘amazing’ and ‘awesome’ appears in my post – that is perhaps an indicator of what a great trip this was. It is not easy to organize a training aboard a cruise ship – there is very minimal electronic communication, which is what we use most of the time for events, there is no ‘common’ place where one can post timetables or itineraries and it is hard to find people when you need them. Despite all these challenges Tim and Amy Ford designed a near flawless schedule with awesome trainers and great networking.

From the time i set foot in the boarding room on Day 1 until the time I actually got into a cab to the airport (oh no wait, I met a couple of people at the airport too 🙂 I was talking and socializing with someone from the group, and that in itself speaks for what a well knit, cool team of people we were together. Do consider the next SQLCruise on your travel/training agenda, it is worth every dime you spend. I surely am considering going on the next one,  already :))

My 3 priorities.. and SQLCruise

I was reading a link recommended by Kevin Kline on Getting Results the Agile way. This author talks of thinking in 3s- setting goals and priorities in 3s and watch how you meet them. If I were to think of 3 things i need to do every year to get ahead in life/career – what would they be?  Mine are as below –

1 Take a vacation – Seems odd that that is the first thing to say for career growth – but to me it is . I was a die hard workaholic for several years in my life – used to think I carried the place on my shoulders, and worried about every single thing that could go wrong if ‘I’ wasn’t around to fix it. Needless to say that didn’t get me anywhere. I ended up really sick with overwork twice, and once even getting fired because the guy on top didn’t like my work ethics (there was more to it than overwork but that was one of the reasons). But after all that the lesson I have learnt is that time away from work is important. Also to add to that – when one reaches mid age one realizes in a very real way that time is limited. That bucket list of places to see and things to do needs to be looked into atleast one a time…after that realization I make it a point to go somewhere atleast once a year and spend two weeks away from work. Sometimes it is my home country, India, sometimes it is other places.

2 Network – I had a speaker in my user group sometime ago. He used to ask me often if I ‘understood’ how networking worked, since he was a rather introverted person himself. After every talk he gave and every meeting he attended he would ‘count’ how many people he had met and if he had gained anything from them. Needless to say after a few meetings he decided there was nothing to this and gave up. I was of the same mindset as this man for a while, since i am also somewhat of a private person and it is hard for me to be ‘out there’…but I was willing to give it a better shot than he. I started the user group locally and after running it for two years – I was approached by someone who attended my meetings with a great job offer. The next two jobs I have landed have been via people I have met, and mostly via conversations rather than formal interviews and resume applications. Networking takes time and effort, but networking pays huge dividends if one is patient and persistent with it. Networking is something I consider I should do with more focus and more diligence as I grow older.

3 Attend as many trainings as possible – As a production DBA I must admit the time I have to learn on my own is somewhat limited. It would be great, as Brent Ozar said once, if the learning is part of the job itself but most DBAs struggle with a lot of operational work – you don’t do cool jazzy stuff every day, you have to do repetitive things and have to attend to a lot of things outside work hours. So the only way really to keep up with learning is to attend trainings – as many trainings as possible. I am a train-a-holic – be it free trainings or paid trainings (my company is generous with paid trainings) – I am there, opening my ears wide to gain as much knowledge as I can possibly gain.

So..the three priorities defined – I found a place where all three can be accomplished in one shot. The SQL Cruise. I get to see Alaska, a place that I have longed to see since I saw pictures of glaciers in my sixth grade geography textbook. I get to network, with some of the most successful and best people in the SQL world (The BrentOzarPLF team, Allen White, Aaron Bertrand,Kevin Kline….). I get to train with them too. Can’t think of anything better that would fit my needs this year and counting every day down to the cruise.

Managing time – a renewed perspective

My favorite book on time management was Stephen Covey’s ‘First Things First’. I say ‘was’ because it has been years since i read it and longer since i used it. There are random quotes and ideas from that book that still stick with me (‘The main thing is to keep the main thing the main thing’,
Sharpen the saw’,’What lies before you and what lies behind you are
much smaller than what lies within you’) and perhaps that is the best i will get out of it. In general, I don’t do well with a lot of structure around time. I don’t think many people do. You can’t run life based on a list – there will always be stuff that is not there, things that get in the way, and many times, you are just plain tired and want to let things be. Covey in fact warns about life becoming one task list after another,and that is exactly what I was facing in this past month. The number of things on my tasklist seemed getting longer and my time getting shorter. Somewhere down the line the focus was lost. I came upon Brent Ozar’s post on time management (http://ozar.me/2012/03/my-6-rules-for-incredible-time-management/) that made huge sense to me during this time. I am writing below on what each of his points meant to me and how I plan to handle my time better.

As a disclaimer, I don’t think many of these will work as is for me. If it did I’d probably be like Brent in my career (MCM and top notch speaker/blogger), and I am not. I have however found it motivating to use long term, infused with the pragmatism it needs for my own needs.

Rule #1: Decide that you want to be incredible. 
The first thought that came to my mind and question I would have asked myself sometime ago is – doesn’t everybody? But from lessons learnt the hard way – no, not everyone wants to be incredible. Atleast not at their careers. They have other priorities/interests, such as families or other hobbies, and that is totally okay. But the cynicism and negativity in many workplaces is so high that words like that are often met with disbelieving snorts and chuckles by most people. ‘I just wanna go home’ or ‘oh please’ would be the most common answer. I am fortunate to work at a place where people do want to learn and training is given the priority it deserves, but that has been my experience in many places. In fact you do not belong if you think higher than they do. 
Takeways: Rise above the cynicism,do not share hopes and dreams with those who have none.

Rule #2: Never budget less than whole-day increments of time.
Can’t believe how grateful I am to hear this articulated..I attended a SQLSkills class early this month. For one week we were in a classroom, with no internet, no cell phones and no distractions. We were purely on a learning high – I find it hard to even say how good that felt , how much I learnt and how well. I often wondered about why I don’t feel that way when I learn on my own – either by reading a book or working on my own lab or watching a video. I get tired easily, want to check out facebook updates, get on twitter, or call a friend. I think i know why, am doing it in really small chunks of time. The bull is not ‘seized by his horns’ , he is wandering around somewhere and can get away real soon. This also somehow ties in with Pomodero technique that Buck Woody recommended (although that is for small chunks of time) – that technique calls for getting comfortable with clock ‘ticking away’,instead of being stressed by it. Both are about focus and getting things done with passage of time. I would say that I am considering ‘big’ increments of time, say 3-4 hours instead of half hour-45 mins – to me particularly that needs to be done for learning and blogging, since that is two areas I want to improve upon.
Takeaways: Experiment with  a bigger chunk of time with a clock.

Rule #3: Leave one whole day per week to do absolutely nothing.
I can proudly say this is one rule I have been practicising a while now and plan to keep. Sunday is ‘my time’ – when I just relax and do what comes to mind, reading,digging in my yard and napping.I also try to keep it offline day, just to get a taste of life without computers running it all the time!!. In short, just plan to keep this one going.

Rule #4: Leave one more solid day per week to pounce on incredible opportunities.
I have been running a user group for 8 years now and organized 4 sql saturdays with #5 en route. This is something I enjoy  and plan to keep doing. But I have not done enough of presenting, especially given the fact that I have an audience to practice on in my own user group.That is an ‘incredible opportunity’, to devote time on. Volunteering does not need one day every week, it comes and goes..during big events it needs more than a day, during normal times perhaps an hour or less. But with more presenting it might take upto half a day..and ties in with #2 – ‘big increments of time’, rather one one more solid day.
Takeaways: Put ‘chunk’ of time into presenting for user group.

Rule #5: If the incredible opportunity runs more than a few weeks, it’s work.
Learnt this the hard way. I cannot study for 2012 beta exams and 2008 mcm knowledge exam at the same time. I cannot volunteer for reviewing speaker extracts and organising sql saturdays at the same time. In short , a lot of things sound sexy but are not doable given the fact that time is limited. Many of them end up as ‘Well begun is half done’. I can prepare for one exam (right now it is the development MCITP which is a pre requsite for the MCM Knowledge exam) and do one volunteering activity (SQL Saturday). After those two are out fo my way I can add on one more in each category but not before.
Takeaways: Get clear on what to do and stick with it, can’t do it all.

Rule #6: Say no early and forcefully to everything else.
Taking on too much is a nasty habit I have been working on kicking, and had some luck this year. It does come with some pain though. I said no to some of things I greatly enjoy – one of them is reading fiction, second is doing an art class (painting/cartooning). Much as I love these things I don’t have time – and if i have to get ahead with SQL some sacrifices have to be made. Doing a little of everything is tempting, but again goes  back to point #2 – the bull wanders away. That is all. (The ‘bull’ as of now is preparing for the development MCITP).

Perhaps the biggest motivator to me is what Brent said about sharpening the saw – or staying up to date on skills. ‘For me, studying and keeping up with technology is part of my work.’. That is what I’d like my work to be – I made a decision 5 years ago that I would not work for a place that did not support a minimum of two solid trainings or conferences per year. That has worked out fine, and helped me hugely with staying up to date. But for me, and for a lot of people, there is a huge element of operational day to day stuff that is part of our jobs and takes away from time we like to use to learn. Production DBAs cannot get away from that easily – it is when you ‘set aside’ time for something that the cluster goes down, or the NOC calls you for some kind of ‘database issue’. Getting to a place where learning becomes part of one’s work is a reward in itself, that speaks volumes for how creative and involved the work is. The goal is to get accomplished enough to deserve that kind of work.

Thank you Brent, for the inspiration.

Meme Monday – February – Working with deadlines

This is in response to Thomas LaRock’s invitation for Meme Monday:

The strategy that works best for is to break the tasks involved into as much detail as possible…so that it makes the final deadline seem far less threatening. I try not to ponder too much on the final product, but work the detail diligently and try to make progress that way.  As a child my father always gave us the example of ants building an anthill – each of them does its job of carrying little pieces of mud/rock, they do not waste time contemplating the big end product. But finally it gets done. I begin with the end in mind, as the saying goes, but like to forget the end until it actually gets close and focus on the detail.

I also attempt not to commit to unrealistic deadlines or set such deadlines for myself. This is something I have learnt the hard way..being a very detail oriented type A person I have set several unrealistic deadlines for myself, and learnt the hard way that they are not doable. There are two issues with setting a realistic deadline – one is having a hard conversation on how much I can do. If my deadline is to attempt a certification, say, how many hours of study can I do? At the end of a long working day, with all home chores done, realistically, am lucky if I do an hour of focused study. If I get too optimistic and make it two I usually wind up getting stressed around finding the two hours and not doing any at all!!  (For work goals it is more around scheduling all the other tasks and explaining honestly to my boss – sometimes he takes something off my plate to help me find more time). The second thing is how much I can do in the given time. In one hour of study time I can probably read a chapter of a book really well..or a portion of the chapter, depending on complexity of the book. Some of this depends on intuitive feel, some of it is plain common sense. So with a good combination of how much i can do and what i can do i can arrive at a good estimate. After that it is just being disciplined and diligent about it. There is nothing better than the good feeling that comes with getting to one’s deadline on time, and having the task done well..that feeling itself is a great motivator.

T-SQL Tuesday #025 – Invitation to Share Your Tricks

This is my first response to a TSQL Tuesday.

There are lot of things in TSQL that can be done to make DBA’s life easier. We have a large collection of scripts. These are some I have used over the years at multiple jobs – there are several more but I don’t particularly want to write a very long post. Also a disclaimer that I did not write all of them.  I wrote some,  I tweaked some I found on sites like SQLServerCentral.com that have come in very handy. I apologize ahead for not offering credit since I have not kept track of the authors.

–Find the last server start date(2005)
SELECT crdate AS Datetime_Started FROM sysdatabases WHERE name = ‘tempdb’

1 –Find Blank passwords
SELECT name FROM sys.syslogins WHERE pwdcompare(””, password) = 1

2 –Find members of a role (for example, public)
SELECT a.[name] + ‘ ‘ + v.[name] + ‘ ON ‘ + QuoteName(oo.[name]) + ‘.’ + QuoteName(o.[name]) + ‘ TO ‘ + QuoteName(u.[name])
FROM dbo.sysprotects AS p JOIN master.dbo.spt_values AS a
ON (a.number = p.protecttype AND ‘T’ = a.type) JOIN master.dbo.spt_values
AS v ON (v.number = p.action AND ‘T’ = v.type) JOIN dbo.sysobjects AS o ON (o.id = p.id)
JOIN dbo.sysusers AS oo ON (oo.uid = o.uid) JOIN dbo.sysusers AS u ON (u.uid = p.uid) WHERE ‘public’ = u.name

3 –Find number of times a stored procedure was used since last reboot
SELECT DB_NAME(st.dbid) DBName
,OBJECT_SCHEMA_NAME(st.objectid,dbid) SchemaName
,OBJECT_NAME(st.objectid,dbid) StoredProcedure
,max(cp.usecounts) Execution_count
FROM sys.dm_exec_cached_plans cp
CROSS APPLY sys.dm_exec_sql_text(cp.plan_handle) st
where DB_NAME(st.dbid) is not null and cp.objtype = ‘proc’
group by cp.plan_handle, DB_NAME(st.dbid),
OBJECT_SCHEMA_NAME(objectid,st.dbid),
OBJECT_NAME(objectid,st.dbid)
order by max(cp.usecounts)

4 –Stick in anything to be changed across all dbs (just used sp_dboption with read only here)
SET NOCOUNT ON

— Get the name of all databases
DECLARE UserDatabases CURSOR FOR

SELECT name FROM master..sysdatabases
where name not in (‘master’,’tempdb’, ‘model’, ‘msdb’, ‘distribution’)

— Open Cursor
OPEN UserDatabases

— Define variables needed
DECLARE @DBase NVARCHAR(128)
DECLARE @COMMAND NVARCHAR(128)

— Get First database
FETCH NEXT FROM USerDatabases INTO @DBase

— Process until no more databases
WHILE (@@FETCH_STATUS = 0)
BEGIN

set @command =’master..sp_dboption @dbname=”’ + @dbase +
”’,@optname=”Read ONLY”, @optvalue=”True”’

— Print command to be processed
print @command

— Process Command
exec (@command)

— Get next database
FETCH NEXT FROM UserDatabases INTO @DBase

END

— Close and Deallocate Cursor
CLOSE AllDatabases
DEALLOCATE AllDatabases

5 —-My favorite, lists job calender

USE MSDB

DECLARE

@JOB_ID VARCHAR(200),

@SCHED_ID VARCHAR(200),

@FREQ_TYPE INT,

@FREQ_INTERVAL INT,

@FREQ_SUBDAY_TYPE INT,

@FREQ_SUBDAY_INTERVAL INT,

@FREQ_RELATIVE_INTERVAL INT,

@FREQ_RECURRENCE_FACTOR INT,

@ACTIVE_START_DATE INT,

@SCHEDULE VARCHAR(1000),

@SCHEDULE_DAY VARCHAR(200),

@START_TIME VARCHAR(10),

@END_TIME VARCHAR(10)

CREATE TABLE #SCHEDULES

(JOB_ID VARCHAR(200),

SCHED_ID VARCHAR(200),

JOB_NAME SYSNAME,

[STATUS] INT,

SCHEDULED INT NULL,

schedule VARCHAR(1000) NULL,

FREQ_TYPE INT NULL,

FREQ_INTERVAL INT NULL,

FREQ_SUBDAY_TYPE INT NULL,

FREQ_SUBDAY_INTERVAL INT NULL,

FREQ_RELATIVE_INTERVAL INT NULL,

FREQ_RECURRENCE_FACTOR INT NULL,

ACTIVE_START_DATE INT NULL,

ACTIVE_END_DATE INT NULL,

ACTIVE_START_TIME INT NULL,

ACTIVE_END_TIME INT NULL,

DATE_CREATED DATETIME NULL)

INSERT INTO #SCHEDULES (

job_id,

sched_id ,

job_name ,

[status] ,

Scheduled ,

schedule ,

freq_type,

freq_interval,

freq_subday_type,

freq_subday_interval,

freq_relative_interval,

freq_recurrence_factor,

active_start_date,

active_end_date,

active_start_time,

active_end_time,

date_created)

SELECT

j.job_id,

sched.schedule_id,

j.name ,

j.enabled,

sched.enabled,

NULL,

sched.freq_type,

sched.freq_interval,

sched.freq_subday_type,

sched.freq_subday_interval,

sched.freq_relative_interval,

sched.freq_recurrence_factor,

sched.active_start_date,

sched.active_end_date,

sched.active_start_time,

sched.active_end_time,

j.date_created

FROM sysjobs j

inner join

sysjobschedules s

ON j.job_id=s.job_id

INNER JOIN dbo.sysschedules sched

ON s.schedule_id = sched.schedule_id

WHILE 1=1

BEGIN

SET @SCHEDULE = ”

IF (SELECT COUNT(*) FROM #SCHEDULES WHERE scheduled=1 and schedule is null) = 0

BREAK

ELSE

BEGIN

SELECT

@job_id=job_id,

@sched_id=sched_id,

@freq_type=freq_type,

@Freq_Interval=freq_interval,

@freq_subday_type=freq_subday_type,

@freq_subday_interval=freq_subday_interval,

@freq_relative_interval=freq_relative_interval,

@freq_recurrence_factor=freq_recurrence_factor,

@active_start_date = active_start_date,

@start_time =

CASE

WHEN

LEFT(active_start_time, 2) IN (22, 23) AND len(active_start_time) = 6

THEN

convert(varchar(2), left(active_start_time, 2) – 12)

+ ‘:’ + SUBSTRING(CAST(active_start_time AS CHAR),3, 2) + ‘ P.M’

WHEN

left(active_start_time, 2) = (12) AND len(active_start_time) = 6

THEN

cast(LEFT(active_start_time,2) as char(2))

+ ‘:’ + SUBSTRING(CAST(active_start_time AS CHAR),3, 2) + ‘ P.M.’

WHEN

left(active_start_time, 2) BETWEEN 13 AND 24 AND len(active_start_time) = 6

THEN

convert(varchar(2), left(active_start_time, 2) – 12)

+ ‘:’ + SUBSTRING(CAST(active_start_time AS CHAR),3, 2) + ‘ P.M.’

WHEN

left(active_start_time, 2) IN (10, 11) AND len(active_start_time) = 6

THEN

cast(LEFT(active_start_time,2) as char(2))

+ ‘:’ + SUBSTRING(CAST(active_start_time AS CHAR),3, 2) + ‘ A.M.’

WHEN

active_start_time = 0

THEN

’12:00 A.M.’

WHEN

LEN(active_start_time) = 4

THEN

’12:’ + convert(varchar(2), left(active_start_time, 2) ) + ‘ A.M.’

WHEN

LEN(active_start_time) = 3

THEN

’12:0′ + convert(varchar(2), left(active_start_time, 1) ) + ‘ A.M.’

WHEN

LEN(active_start_time) = 2

THEN

’12:00:’ + convert(varchar(2), left(active_start_time, 2) ) + ‘ A.M.’

WHEN

LEN(active_start_time) = 1

THEN

’12:00:0′ + convert(varchar(2), left(active_start_time, 2) ) + ‘ A.M.’

ELSE

cast(LEFT(active_start_time,1) as char(1))

+ ‘:’ + SUBSTRING(CAST(active_start_time AS CHAR),2, 2) + ‘ A.M.’

END,

@END_TIME= CASE

WHEN

left(active_end_time, 2) IN (22, 23) AND len(active_end_time) = 6

THEN

convert(varchar(2), left(active_end_time, 2) – 12)

+ ‘:’ + SUBSTRING(CAST(active_end_time AS CHAR),3, 2) + ‘ P.M’

WHEN

left(active_end_time, 2) = (12) AND len(active_end_time) = 6

THEN

cast(LEFT(active_end_time,2) as char(2))

+ ‘:’ + SUBSTRING(CAST(active_end_time AS CHAR),3, 2) + ‘ P.M.’

WHEN

left(active_end_time, 2) BETWEEN 13 AND 24 AND len(active_end_time) = 6

THEN

convert(varchar(2), left(active_end_time, 2) – 12)

+ ‘:’ + SUBSTRING(CAST(active_end_time AS CHAR),3, 2) + ‘ P.M.’

WHEN

left(active_end_time, 2) IN (10, 11) AND len(active_end_time) = 6

THEN

cast(LEFT(active_end_time,2) as char(2))

+ ‘:’ + SUBSTRING(CAST(active_end_time AS CHAR),3, 2) + ‘ A.M.’

WHEN

active_end_time = 0

THEN

’12:00 A.M.’

WHEN

LEN(active_end_time) = 4

THEN

’12:’ + convert(varchar(2), left(active_end_time, 2) ) + ‘ A.M.’

WHEN

LEN(active_end_time) = 3

THEN

’12:0′ + convert(varchar(2), left(active_end_time, 1) ) + ‘ A.M.’

WHEN

LEN(active_end_time) = 2

THEN

’12:00:’ + convert(varchar(2), left(active_end_time, 2) ) + ‘ A.M.’

WHEN

LEN(active_end_time) = 1

THEN

’12:00:0′ + convert(varchar(2), left(active_end_time, 2) ) + ‘ A.M.’

ELSE

cast(LEFT(active_end_time,1) as char(1))

+ ‘:’ + SUBSTRING(CAST(active_end_time AS CHAR),2, 2) + ‘ A.M.’

END

FROM #SCHEDULES

WHERE schedule is null

AND scheduled=1

IF EXISTS(SELECT @freq_type WHERE @freq_type in (1,64))

BEGIN

SELECT @SCHEDULE = CASE @freq_type

WHEN 1 THEN ‘Occurs Once, On ‘+cast(@active_start_date as varchar(8))+’, At ‘+@start_time

WHEN 64 THEN ‘Occurs When SQL Server Agent Starts’

END

END

ELSE

BEGIN

IF @freq_type=4

BEGIN

SELECT @SCHEDULE = ‘Occurs Every ‘+cast(@freq_interval as varchar(10))+’ Day(s)’

END

IF @freq_type=8

BEGIN

SELECT @SCHEDULE = ‘Occurs Every ‘+cast(@freq_recurrence_factor as varchar(3))+’ Week(s)’

SELECT @schedule_day=”

IF (SELECT (convert(int,(@freq_interval/1)) % 2)) = 1

select @schedule_day = @schedule_day+’Sun’

IF (SELECT (convert(int,(@freq_interval/2)) % 2)) = 1

select @schedule_day = @schedule_day+’Mon’

IF (SELECT (convert(int,(@freq_interval/4)) % 2)) = 1

select @schedule_day = @schedule_day+’Tue’

IF (SELECT (convert(int,(@freq_interval/8)) % 2)) = 1

select @schedule_day = @schedule_day+’Wed’

IF (SELECT (convert(int,(@freq_interval/16)) % 2)) = 1

select @schedule_day = @schedule_day+’Thu’

IF (SELECT (convert(int,(@freq_interval/32)) % 2)) = 1

select @schedule_day = @schedule_day+’Fri’

IF (SELECT (convert(int,(@freq_interval/64)) % 2)) = 1

select @schedule_day = @schedule_day+’Sat’

SELECT @SCHEDULE = @SCHEDULE+’, On ‘+@schedule_day

END

IF @freq_type=16

BEGIN

SELECT @SCHEDULE = ‘Occurs Every ‘+cast(@freq_recurrence_factor as varchar(3))+’ Month(s) on Day ‘+cast(@freq_interval as varchar(3))+’ of that Month’

END

IF @freq_type=32

BEGIN

SELECT @SCHEDULE = CASE @freq_relative_interval

WHEN 1 THEN ‘First’

WHEN 2 THEN ‘Second’

WHEN 4 THEN ‘Third’

WHEN 8 THEN ‘Fourth’

WHEN 16 THEN ‘Last’

ELSE ‘Not Applicable’

END

SELECT @SCHEDULE =

CASE @freq_interval

WHEN 1 THEN ‘Occurs Every ‘+@SCHEDULE+’ Sunday of the Month’

WHEN 2 THEN ‘Occurs Every ‘+@SCHEDULE+’ Monday of the Month’

WHEN 3 THEN ‘Occurs Every ‘+@SCHEDULE+’ Tueday of the Month’

WHEN 4 THEN ‘Occurs Every ‘+@SCHEDULE+’ Wednesday of the Month’

WHEN 5 THEN ‘Occurs Every ‘+@SCHEDULE+’ Thursday of the Month’

WHEN 6 THEN ‘Occurs Every ‘+@SCHEDULE+’ Friday of the Month’

WHEN 7 THEN ‘Occurs Every ‘+@SCHEDULE+’ Saturday of the Month’

WHEN 8 THEN ‘Occurs Every ‘+@SCHEDULE+’ Day of the Month’

WHEN 9 THEN ‘Occurs Every ‘+@SCHEDULE+’ Weekday of the Month’

WHEN 10 THEN ‘Occurs Every ‘+@SCHEDULE+’ Weekend Day of the Month’

END

END

SELECT @SCHEDULE =

CASE @freq_subday_type

WHEN 1 THEN @SCHEDULE+’, At ‘+@start_time

WHEN 2 THEN @SCHEDULE+’, every ‘+cast(@freq_subday_interval as varchar(3))+’ Second(s) Between ‘+@start_time+’ and ‘+@END_TIME

WHEN 4 THEN @SCHEDULE+’, every ‘+cast(@freq_subday_interval as varchar(3))+’ Minute(s) Between ‘+@start_time+’ and ‘+@END_TIME

WHEN 8 THEN @SCHEDULE+’, every ‘+cast(@freq_subday_interval as varchar(3))+’ Hour(s) Between ‘+@start_time+’ and ‘+@END_TIME

END

END

END

UPDATE #SCHEDULES

SET schedule=@SCHEDULE

WHERE job_id=@job_id

AND sched_id=@sched_Id

END

SELECT job_name ,

[status] = CASE STATUS

WHEN 1 THEN ‘ENABLED’

WHEN 0 THEN ‘DISABLED’

ELSE ‘ ‘

END,

scheduled= case scheduled

when 1 then ‘Yes’

when 0 then ‘No’

else ‘ ‘

end,

schedule as ‘Frequency’ ,

convert(datetime, convert(varchar,active_start_date, 101)) AS schedule_start_date,

convert(datetime, convert(varchar,active_end_date, 101)) AS schedule_end_date,

date_created

FROM #schedules

WHERE scheduled=1

ORDER BY job_name

DROP TABLE #schedules

I hope you all find something useful. And thank you to Allen White for hosting.

SQL Server 2012 – Changes to set up

I plan to write a series of posts while learning more on SQL Server 2012. The changes to set up as I observed while installing SQL Server 2012 RC0 are :

1 Pre requisites include Powershell 2.0 and .NET Framework 3.5
2 If you have Windows 7/Windows Server 8/Office 2010 it expects Service Pack 1 to be installed (does not even proceed until pre requisites if not).

The install is a slipstream process – by that all the necessary pre requisites are part of the media, there is no need to go to separate sites to download/install.
3 There is no reboot required upon install (I only tested it as standalone, with all other programs closed – this may not be true in a cluster install).

4 32 bit install is still supported.
5 Support for Itanium appears to have been removed.

Acknowledgement:

I was inspired to learn more and write by Aaron Bertrand’s presentation on New Features at the PASS conference 2011(http://sqlblog.com/blogs/aaron_bertrand/archive/2011/08/07/sql-server-v-next-denali-changes-to-system-objects-in-ctp3.aspx)

ON SQL Family…

Contributing to Thomas LaRock’s Meme Monday:

I had an interesting experience at the recent SQL Saturday in Louisville. A young man came up to me at lunch and asked me –
Him: ‘So, how long have you been doing this?’
Me: ‘3 years now, this is our third event’
Him:’Wow, great job!’
Me:’Thank you’
Him:’If you don’t mind me asking, is it good money on the side?’
Me:’Sorry?’
Him:’I meant, PASS pays you right, this is a lot of work, organizing this and all this, am guessing organizers and speakers get paid?’
Me:’No we don’t get paid,nobody makes anything off of this’
Him:’Are you serious? These speakers, they all come in for free?’
Me:’Yes, everyone does. Many pay their airfare and accomodation all out of their pocket to come’.
Him:’So you guys all take your personal time and effort for something like this? I have been with MS communities for years, never seen anything like this..Wow, i mean am speechless, wow!, I mean it is a huge effort, how do you find motivation?’
Me: ‘Yes the SQL community is unique, we are family, in more ways than one. We believe in sharing our knowledge and our success and help everyone grow. If you had to organize a family reunion, would you go about doing it or make a huge deal of how much effort it is and how you are not making a dime out of it?’
Him:’Guess I’d do it…I guess you guys are a great family like community, wow, hats off to you all, and thank you. I want to be part of this, I do. Wow, am not over it yet. ‘

I guess that kind of summarizes the SQL family, in more ways than one. We get it done, for the love of it. And we stick together through thick and thin. What more could one ask for?