A Simple Update Statement

I had a new developer this week ask me a good way to write an update statement with a join across two tables.  He was new to set based processing only having worked with procedural logic in code.  Set based allows you to update many rows all at the same time and is almost always faster than doing each row one by one.  His suggestion of using a cursor to update every row just wouldn’t have worked well.

After explaining what set based processing was I also showed him a simple trick I’ve always used to write my set based update statements.  I’ve added a simple script below and I’ll walk through what I typically do to write the statements.

The simplest method I’ve always found is to just write a normal select statement with the join’s you need and all the columns you want to see and then replace the select statement at the top with an update statement.  This lets you see the data and test that the data is exactly what you want to update.  I’ve enclosed a script showing this simple method and how I use it.  Hopefully it will make your life a little easier as well.

———————————————————————–
–Simple Setup section

Create table #toBeUpdated
(id int identity(1,1) not null Primary Key,
Keycolumn varchar(255) not null default ‘Tasty’,
UpdateColumn varchar(255) null
)

Create table #UpdateValue
(id int identity(1,1) not null Primary Key,
Keycolumn varchar(255) not null default ‘Tasty’,
UpdateValueColumn varchar(255) null default ‘Bacon’
)

Insert into #toBeUpdated (Keycolumn) values (Default)
Insert into #UpdateValue (Keycolumn,UpdateValueColumn) values (Default,Default)
———————————————————————–
–How the original table looks
Select * from #toBeUpdated
———————————————————————–
–this shows what column needs to be updated and what it will be updated to
Select
Upd.Keycolumn,
Upd.Updatecolumn as SourceUpdateColumn,
Upv.UpdateValueColumn as TargetUpdateColumn
from
#toBeUpdated as Upd
join
#UpdateValue as Upv
on
upd.Keycolumn = upv.Keycolumn
———————————————————————–
–To create the update statement simply comment out the select statement and
–write the update at the top.
Update #toBeUpdated
Set UpdateColumn = Upv.UpdateValueColumn
–Select
– Upd.Keycolumn,
– Upd.Updatecolumn as SourceUpdateColumn,
– Upv.UpdateValueColumn as TargetUpdateColumn
from
#toBeUpdated as Upd
join
#UpdateValue as Upv
on
upd.Keycolumn = upv.Keycolumn

———————————————————————–
–shows the results of the Update
Select * from #toBeUpdated

DBA Job Hunting Tips Part 2

I wanted to follow up to this post DBA Job Hunting Tips.  I received a resume from one candidate that I really liked how they organized the information about themselves.  It went in line with many of the things from that first blog post.  The candidate didn’t want to share the resume so I simply made a new header for my resume and will use that.  Below is an example of a really simple clean header that gives me all the information I need to look this person up online and saves me a lot of time.

As you can see I listed out my blog, Twitter feed and LinkedIn profile.  This gives the person looking at this resume easy access to all the work related information they need for me online.  If you speak often a link to your SpeakerRate profile would be a good idea as well.  You should always go out of your way to make it easy for a hiring manager to find information about you.   That person may be going through hundreds of resume and saving the hiring manager time is a good idea.

Since I’ve been doing interviews all week here are a few tips as well.

  1.  Be passionate!  Make it sound like you really want to work here you are applying for the job so I’m assuming you really do want to work here.  This is a very important point for me.
  2. You will not have all the answers, Let me make that 100% clear you will *NOT* have all the answers.  Don’t  be afraid to say I don’t know but I have these resources to use at my disposal (google,twitter,blogs,friends and etc…) and describe how you would find the answer.
  3. Don’t afraid to be technical.  You may be doing an interview with a HR person that doesn’t know SQL from Perl.  Don’t be afraid to ask how technical do you want me to go?  List out direct statements if you can or if they want a technical answer.
  4. Be early.  Notice I didn’t say on time.  Again show me that you want to work here if you are excited and really want to work here then you need to show me that.
  5. Practice!  Hold mock interviews with your friends.  Go present at a user group to get used to talking in front of people. If you can get in on doing an interview I suggest it to get another perspective.
  6. Keep a clean appearance,  If this is a phone interview you can ignore this but sooner or later you’ll need to do a in person face to face interview when that happens dress appropriately.  I’m not a big fan of a suit and tie for interviews typically because I’m interviewing developers / DBA and we don’t normally wear that every day in our work environment. Wear something you will be comfortable in but still looks professional.  Bonus points if you wear a really geeky shirt like from www.thinkgeek.com.

The key item on this list for me is #1.  When someone does not a question I see that as a teaching opportunity for a candidate that really wants to learn.  If the person is not passionate then I’m assuming they don’t want to learn and don’t want to move forward with the career they have chosen.

These tips are very subjective as everyone interviews and hires people differently this is what works for me and what I look for but no matter who you are talking to if you are passionate about the subject it will show.

DBA Job Hunting Tips

Wow 4 months without a blog post.  I’ve been a lazy blogger.   :)

In reality this seems to happen to me when I start a new job.  I get so focused on creating a new project I lose a lot of time to write blog posts or participate in social networks.   I’ve taken on a few new contracts as well and volunteer items so it’s been a busy 4 months for me.  I’m going to try and get into the habit of writing up a blog post a week.  I have 2-3 already written/drafted so those should get scheduled in the next few weeks.

At my last job I was responsible for hiring a new DBA for the team.  I’m in the same position at my current company and am looking for a DBA.  I’ve gotten a few resumes already and just wanted to share what I typically go through to review candidates.  Now keep in mind this is before I have talked to them, emailed them or scheduled some sort of interview.

  1.  Google the candidates email address.   I look at the results returned but also look at the discussions list to find what Google groups they might have been asking questions in and what kind of questions.
  2. I search on Linked in by the name of the person.  Google can find this as well I like to put a location behind the name like SLC so it finds the local person.  That is of course if the person is local.
  3. I review what I find from Google and LinkedIn.  If they are on LinkedIn I find out who else is in my network I can possibly ask for a review.  I review the information listed on LinkedIn and the reviews they have gotten from other members of LinkedIn.
  4. If they have blogs/twitter and I can find that from the email or name that was given then I review that information as well.

These are the typical steps I do before even calling/speaking with a candidate.  This doesn’t mean that I’m not going to interview someone just because of what I find.  It just provides me with more information about the candidate.

So if you are out there looking in the market for a DBA position (like this one! (http://www.allegiance.com/company/career-opportunities#da) I would suggest placing this information clearly on your resume so that it’s easy to find.  It will at least make my life easier and I’m sure others will appreciate it as well.

What gift do I want MS to leave under the tree? (#Meme Monday from SqlRockstar)

Thomas Larock (aka @Sqlrockstar (Blog) )   has set a new question for this month’s #meme Monday.  You can read his original blog post here.  This month’s Question, “What gift do you want Microsoft to leave for you under the tree this year?” the simple answer is that I don’t want them to leave me a gift I want them to leave you a gift.

When I was a MVP many moons ago I was fortunate it enough to attend the MVP Summit in Seattle this is an annual gathering of all the MVP’s that get together and help MS improve their products and give feedback about the way they are doing things.  When I was there we were discussing SQL Server 2005 and what should be in each SKU/Product level (Standard, Workgroup, and Enterprise Editions).  We knew some of the new features that were coming out as Mvp’s and they wanted to get our take about where they should fall.  As MS read the different features it was unanimous most of the killer features we really wanted in the standard edition of the product since we knew lots of companies could benefit from that.  Not surprisingly when 2005 was released most of the features discussed ended up in enterprise edition.  What I would like to give everyone for Christmas is for the next release to balance this out a little better.  Every cycle Microsoft talks about the greatest features that are ready to come out during presentations and never mentions what edition they will be in until someone asks the question.  Go to most presentations from MS about new features and you tell me if they mention what versions they will be in until someone asks the question.

Now please don’t get me wrong, MS is a business and the job of the business is to make money.  I’m not saying they are not allowed to make money.  What I would like for everyone on Christmas from MS is for them to stop the smoke and mirror show and give it to us truthfully!  Tell us the HA features of 2012 will only be available in enterprise edition at the beginning of the presentation.  Why do I want this?   So I can go back to my desk and figure out ways to make my system work without these features since I only have Standard edition to use.  So I don’t have to spend an hour in a presentation with a technology I’m not going to be able to use.  Yes you will see me researching these new features and even presenting on them in the future but I will tell you the edition it applies to.  So you know whether this will be useful or not given your current situation.  Just a simple request to be clearer when you’re telling us that you made a new function that can give us Rainbows and Unicorns out of the DB.

I think it’s a simple Christmas wish. :)

Hope everyone finds this under their tree this year.

 

Policy Based Management Simple Tip!

I’m just starting out looking at Policy based management for SQL Server 2008.  I haven’t had a large SQL Server base to manage recently so I haven’t really had a chance to use it.  Where I’m at currently I’m the sole DBA and have about 300+ Databases that have had less than perfect maintenance and setup done to them so I figured I would test out PBM to get some things in order.

I noticed that many of the Databases were set to grow in 1mb increments.   That’s fine and dandy to make a fast Auto Grow time but my VLF files are off the charts on this server. I know the real solution is managing the space and growing when I want to in size/chunks when I want to.  For right now though with the 50 other tasks I have on my plate I wanted to knock this one out quickly.

Adding the policy was easy this post does a great job of showing you how to do this.    The problem I ran into was finding the proper Facet.   In this case you can find @growth in the Data File Facet.   The second mistake I made is I tried to say in the check condition I wanted to find everything that’s not equal to 512.  I figured that would give me a list of all my Databases out there.  But that’s not what PBM wants.  PBM wants you to tell it what the number should be and it will tell you who doesn’t match.  When I said not equal it wouldn’t let me apply that after I got my list.  Once I changed the rule to = 512 it found me all the databases I was looking for and allowed me to apply the change to set them to grow at 512 instead of 1.

Make sure when you are creating a PBM policy make your items equal to what you are looking for instead of not equal.

Thank you to @sacSqlDude and @johnsterrett on twitter for helping me out today and telling me what I needed to do!

SQL Family

Thomas Larock aka @SqlRockstar (Blog|Twitter) has put on a monthly meme with a different topic each month.  I’ve decided to participate in this topic as it’s an important aspect of my life.Thom asks “Write about what #sqlfamily means to you.”#SqlFamily started for me way back in 2003.  I was a DBA at a large health care organization and I heard about a SQL users group starting in my area I wanted to check it out since any help I could get in my current role as a DBA would be great.  I started to attend the meetings and found others that enjoyed SQL Server as well.  This then lead me to start presenting and shortly after attending my first PASS Summit.  At the summit I met even more people like me that not only enjoyed SQL Server but gave of their time freely to help others.For me the #SQLFamily has always been about people helping people.  The community is very giving to everyone.   There is no membership in this family, it’s never a question of have you been here before or are you a “regular”  it’s the place that welcomes you with open arms regardless of who you are or what you do.  If you have a problem we’ll help you try and solve it.  It’s that simple it’s that easy.  To me that’s #SQLFamily.

The family extends so much further than a discussion forum or a specific website.  It’s there when your son/family member is in the hospital and you need some positive reinforcement.  It’s there to wish you congratulations when a new baby is born or you celebrating sending your kids off to college.  It’s people taking care of each other and looking out for one another.

To answer Thom’s original question.  #sqlfamily means people helping people.  Something I think all families should strive to do more often.

DBA Week 2 A follow up to your first day.

I wanted to get a follow up post to my recommendations for DBA’s for the first day on the job post.   After a very busy week last week here is where I stand on my list and what I should add for the next week.

  1.  Get a list of Servers I’ll be managing/owning: I’ve got the list, can’t say I have access to all of them but working through that.
  2. Run the SP_Blitz: I’ve got this done on several servers and honestly haven’t done a ton of analysis on it yet.  Still high on the list.
  3.  Get a DBA database created on each server: Done for known servers.
  4. Create the server side trace: Done for the primary prod servers.
  5. Create perfmon counters: Done for the primary prod servers.
  6.  Install SSMS tools pack: Done (and it’s already saved me),
  7. Check the backups/backup schedule: Taken care of by a managed host provider, many changes in store for this one.
  8. Check the security model and who has access to the DB: Figured out most of this and some changes are in plan for the future as well.

Things to Add after your first week.

  1. Developer communication/training.  We have a developer training planned this week and I’m prepping a presentation based on performance tuning and some of the procedures I’ve worked on over the last week.   It’s a great time to start building relationships with the DEV team and working with them to improve the app and server even more.
  2. Slow procedures/query tuning.  Now that you’ve had your trace and performance counters in place start researching what you can do to improve the performance of the server.   Perhaps hardware is needed or memory settings need to be changed.   We saw a big increase because of a server mis-configuration in the memory settings.
  3. DMV’s,  I want to get these into the first week list but didn’t have a chance and don’t have an automated procedure but am researching some right now and plan to have them running in the next week.  Capturing query info and index info in DMV’s are key.
  4. Optimizations, unfortunately there is still a lot of mis-informaiton out there about what needs to be re-indexed/rebuilt and checked.  I’ve found a very heavy optimization job running on the servers and need to re-factor this to really help the performance of the server.  This is top on my list as it’s running into prod time and needs to get fixed.  I’ve also found Shrink jobs running (never a good thing).
  5. Last major suggestion for this week is be cautious.   You’ll find lots of things that you want to change and you may be tempted to start making wide sweeping changes but be careful.  If your systems haven’t been looked at by DBA eyes for a while then making large sweeping changes could have a huge impact on the system.   Make sure to document and test anything you put into place.  One method I use for this is getting a mailbox setup that I can email my changes to and store them that way I have a history.  If you have a Team of DBA’s with you this works well to inform all of them at once.

Hopefully I’ll get a chance to blog out mid next week with some of the scripts I’ve been talking about.   Let’s see how this week 2 goes for me. :)