All posts by Sean McCown

I am a Contributing Editor for InfoWorld Magazine, and a frequent contributor to SQLServerCentral.com as well as SSWUG.org. I live with my wife and 3 kids, and have practiced and taught Kenpo for 22yrs now.

New Language Services

The new version of SSMS takes advantage of the new language services that the team has been working on for so long now.  So far it’s actually looking pretty good.  You can finally refactor columns throughout all of your code because the language service comes directly from the engine it knows everything about the code you’re looking at.  It’s more of a dev feature, but plenty of DBAs will find this useful as we all wind up doing dev anyway. 

There’ll be more on that in the future, but I just wanted to write this blurb to let everybody know that the language service is coming along.  This is the first real step in bringing us a much better intellisense.  Does that mean you’ll no longer need Red-Gate’s tool?  No, because SSMS still won’t format your code for you or do some of the other cool things SQLPrompt will do.  Things like * expansion, and uniform table aliases are just 2 of the things Red-Gate brings to the table.  Unfortunately for them though, the new SSMS will start to close the gap so they’ll have to come up with something else if they wanna stay in that game.

FileTable is here

FileTable is another new feature in Denali.  FileTable is the next generation of FileStream.  What this allows you to do is copy files into specified folders on your server, and they automatically get stored in SQL.  So you define a FileTable in SQL and point it at a folder.  Now, anything you put in that folder, shows up in the DB itself.  You can still view the files directly from the file system, only when you do, you’re actually reading them out of the DB.  So we’re really starting to obscure the line between DB and Windows. 

This is one of those features that’s really cool.  To be able to drag a group of files into a folder and have them automatically added to the DB is really cool.  Not only can you add/delete them, but you can also modify them.  You can set file properties using t-sql and it’ll persist that change to the file system.  So now I have to wonder what the future of powershell will be because working with a large amount of files is something we do with powershell the most.  It’s one of the things powershell does really well.  But now that we’ve got this, if we’re able to define a folder as a DB table, then we don’t have to use powershell for these types of file ops anymore… we can just use set-based t-sql. 

The possibilities are churning in my head.

Always On

I’m here at the keynote for day 2 of PASS and we’re watching a demo of their new Always On feature for Denali.  And it all looks well and good, but I can’t help but wonder what’s wrong with it.  Always On gives you the ability to define HA groups and in just a few clicks you can configure automatic failover, and synch to multiple servers.  Again, that all looks fine up on stage, but I, like many others, am witholding any opinion until I get in there myself.  I’m sure we all remember the dacpac fiasco.  It looked wonderful on stage and even I was very excited about it.  But when we all went to play with it we found out very quickly that it had more problems than solutions.

Trust me, I’ll be writing plenty on this in the future.

Slow Start at PASS

Well, PASS got off to a rocky start… well,  for me anyway.  It started with of course not being chosen to speak, which is fine really.  Plenty of people don’t get chosen so I’m good with that.  I did have one of my sessions put on the reserve list though.  However, they actually needed to pull someone from the reserve list and they asked Jen to teach a 2nd one instead of pulling me in.  Ok, that hurt, but I’m alright.  I’ve still got a good attitude about the event.  I’m good.  Then I got here and they wouldn’t give me a conference bag.  Alright, now this is just ridiculous.  So I don’t have a conf guide because they’re in the bags.  On top of that they didn’t have me listed as an MVP.  Then I didn’t have an Alumni ribbon.  That’s not the biggest deal, but Jen’s only been here twice and I’ve been coming for a decade and she got one.  Next I didn’t have a spot at the blogger table at the keynote.  I’ve been a blogger here for years and I’ve had a spot at the blogger table for years and I even answered the email saying, yes, I want my spot at the table.  Jen got her spot, where’s mine?  There are lots of bloggers at the table I’ve never seen at the table before, and yet I don’t have a spot.  Jen went to complain in the press room, and today I have a spot, but now it’s like I’m just this whiny little baby who cried and got his way.  And I don’t want it to be like that. 

Apart from all that, I’m still having a good time.  I’m putting this conspiracy to make me cry behind me and just doing my thing.  So PASS kicked off to a slow start for me, but all’s well.

Trace flag 1807

This is something I haven’t had a use for in quite some time but it actually came in handy today.  Of course, this isn’t something you’d want to make a living doing, but you’ll love to keep it in your hat and pull it out every couple yrs or so when the situation arises.

This is all about solving problems.  Here’s the scenario.  A vendor is here and he’s trying to upgrade a DB schema.  The way the thing works is it basically copies the entire DB to new tables and then drops the old ones.  So at the apex of the operation the DB is about double in size.  The problem is that the server doesn’t have enough space to hold double the DB.  So what do you do?

Well, one of your options is to add space to the disk.  The problem there is that you can never just add space, right?  You have to provision it, etc.  So in this scenario this isn’t a good option at all.

Next you could find another SQL box on the same build and move the DBs over there.  You could then perform the upgrade on the other server, and then move the files back when you’re done.  Of course, the problem there is finding another box that doesn’t encroach on someone else’s production.  So you may or may not have this type of box lying around.

You could also think about just moving the files over to like a SAN or another server that has enough space and just attaching them across the wire.  So the way that would look would be for you to move the files to the other server (assume it doesn’t have SQL installed because you don’t need it), then attach the DB from the original server and point it back to the UNC path where the files are now.  Then once the conversion is done, all you have to do is move the files back to the original server and you’re golden.

But wait… there’s a problem.  If you attach files across the network, SQL will run a check that they’re not local and throw an error.  And even if map a drive you’ll get the same result.  So how can we get around SQL checking for network locations?  That’s where trace flag 1807 comes into play.  Just typing a simple DBCC TraceON (1807) and then attaching your files will disable the network check and allow you to attach your files.

Pretty cool huh?

And for those of you who like to see things in action, I’ve got this video of how this all works.

http://midnightdba.itbookworm.com/VidPages/Trace1807/Trace1807.aspx

My morning so far

Ok, aside from being kinda sick still, my morning has been filled with interesting issues.  Ahhh– the life of a prod DBA. 

It started today with space issues–again.  We’re just running out of space everywhere and it’s hard to even keep some DBs running because of the problems.  So I’m having to shrink some DBs just to keep them active. 

Now this one just gets me a little.  Had a vendor come up to me to ask for help.  He was on one of the prod servers and detached 3 of the DBs and couldn’t get them back.  Turns out he had moved the files and renamed them and expected SQL to know where they were.  He said he had problems initially and that’s why he did it, but he got stuck when he couldn’t detach them again to point SQL to the new files.  So I got that worked out for him with relatively little effort.  

Now this next one is just interesting.  I just switched our backup routine on our big system to backup to 20 files.  So the dev downstairs had a routine to restore it to a different server (I didn’t know that) and his routine was bombing.  He had re-written it to use the 20 files, but it was still failing.  Now, I’ll say that doing it the way he did doesn’t make him dumb.  In fact, I could very easily see anyone making a similar mistake because to someone who doesn’t know backup intimately, it seems like the kind of thing you should be able to do.  What he did was he was building a dynamic string to hold the file name values.  So in the string he was saying something like this: 

  

SET @BackupDatabaseFileNamePath = ‘DISK = N’ + ”” + ‘\\’ + @ProdIP + ‘\’ + LEFT(@BackupDatabaseFileNamePath,1) + ‘$’ + 

RIGHT(@BackupDatabaseFileNamePath,(LEN(@BackupDatabaseFileNamePath)-2)) + ””  

And so to that end, he was ending up with a string that looked like this: 

DISK = ‘\\127.0.0.1\K$\SQLBackups\ServerName\DBName\01of20FullPRD20101102010001.BAK’, 

And he did that 20 times, once for each file.  So now his actual restore command looked like this: 

  DECLARE @file VARCHAR(100) 

SET @file = ‘c:\SSISPkgMgmt.bak’ 

RESTORE DATABASE SSISPkgMgmt 

FROM @file 

WITH replace 

RESTORE DATABASE PRD 

FROM @BackupDatabaseFileNamePathInc 

And that looks like it should work because when you print it, you wind up with a perfect backup cmd.  The problem is that the backup cmd doesn’t work like that.  It takes params, or flags if you will, right?  And one of those flags is ‘DISK =’.  That means that the flag itself is ‘DISK =’, not a string that contains that same text.  It’s a subtle difference to us, but not to the backup cmd.  So if you want to build a string like that for either a backup or a restore, then you have to build a string that contains the entire backup cmd and not just a single part that includes the params. 

Here’s an example of something you can do though: 

DECLARE @file VARCHAR(100

SET @file = ‘c:\SSISPkgMgmt.bak’ 

RESTORE DATABASE SSISPkgMgmt 

FROM @file 

WITH replace 

And what he was trying to do was this: 

DECLARE @file VARCHAR(100)
SET @file = ‘DISK = ”c:\SSISPkgMgmt.bak”’
 
RESTORE DATABASE SSISPkgMgmt
FROM @file
WITH replace

 
If you run something like this you’ll see that SQL views it as a backup device because that follows the restore syntax.

So anyway, big fun again today too.

My ridiculous day

Yeah, some days it just doesn’t pay to even try to do a good job.  Not only are my sinuses really giving me a raging headache today, but these are the ridiculous things I’ve been engaged in on top of it.

I had to tshoot an ssis pkg because it stopped working when I moved it to the dev box.  As it turns out the moron who wrote it put the values in the config file like I told him to, but he only put part of them in there.  The rest are still hardcoded in the pkg so of course it was failing.

I’m installing SQL R2 ent. on a VM with 1GB of RAM.

I turned AutoShrink back on for a DB because the business owner is scared to death it’ll blow something up if I don’t and they wanted to check with the vendor to make sure I wasn’t going to kill the DB.  Shoot me now.

I BCPd a couple large tables out to a different server and zipped them up.  I had to do this because the server is running out of space and the server team says they can’t get any more right now.  So in order to keep the DB running I’ve had to take a couple tables out of the DB so there’s room for normal ops.  This won’t end well.

Heard back from the support guy about the AutoShrink issue above.  He’s not sure but he’s pretty sure that a major change like that will void our support contract.  Really?  On the day my head is pounding so hard?  Consider yourself lucky this time.

Going to lunch soon.

Another Interview

Ok, I just got out of another interview earlier today and there are a couple good ones in here.  It’s not anywhere near as good as the last one, but you’ve gotta admit that’s a tough act to follow.  So this girl was much more business-like and she was quite nice and honestly just trying to do her best.  She was quite shy and Asian so her english wasn’t the best.  So I’m forced to interpret her answers as best I can sometimes.  So I honestly can’t tell you exactly what she said for all of them, but I’m getting the gist as best I can from the different things she want through to try to reason it out.  I typically just landed on the last thing she said and took that as her answer.

Q:  What the difference between an SP and a trigger?

A:  A trigger is a special SP that stops when you run it after a certain time.  They can only run for a pre-determined time.

Me:  Oh yeah?  Ok, so how long can they run?

Her:  It depends on how big the server is.  It’s determined by the resources.

Q:  what’s the difference between datetime and smalldatetime?

A:  Smalldatetime is limited and datetime is much more range of time.

Q:  What does sp_ in front of an SP signify? 

A:  It just means that it’s an SP.  All SPs have to be named sp_ or the system won’t read them as SPs.

Q:  What are the 2 types of UDFs?

A:  Fixed and variable.

Me:  Ummm, ok.

Q:  What’s the difference between ‘Select Into’ and ‘Insert Into”?

A:  Insert puts data into a table… select into… (she struggles with the answer and half says a couple things.  She then fades out after saying about 3 things I couldn’t understand.  None of them sounded like an answer though.)

Q:  What’s the difference between varchar and nvarchar?

A:  International support.

Q:  What’s the difference between a clustered index and a non-clustered index?

A:  Cluster is a pair index.  It’s at the server level so when something is down it’s kind of like a backup.  Non-clustered  in the only one…(something I can’t understand)… you can rely on that one and only backups can support it.

 

I then told her to give me a question to ask her.  “I want you to pick the next one.  Give me a specific question to ask you.”

And after thinking for a minute or so she comes up with this:

“What does DML stand for?”

So I asked her that question, and after fudging around for over a minute she finally came up with the right answer.  She went through many variations before landing on the right answer though.

Ok guys, that’s it for this round.

The Dumbest man on Earth -char() vs varchar()

Wow, I didn’t realize I left this question out.

So here’s the question:

Q:  What’s the difference between char() and varchar()?

A:  With char() you can store the standard set of characters.  And with varchar() you can store the extended set… pretty much any character you can think of can be stored in varchar() whereas with char() you can only store the standard 50.  I think it’s 50.  Maybe it’s 53 or something.  I forget the exact number, but it’s about 50. 

So that’s when I asked him about the difference between char() and nchar() because that usually kicks them in line and they go, oh wait, y, so char() holds regular data and nchar() holds extended data.  So that means varchar() holds… and then whatever they come up with next.

But not this guy, no, he stuck to his guns and went with nchar() holding numeric character data.

You’ve gotta love someone who sticks to their guns no matter what!

The Dumbest man on Earth -Another Short Note

Sorry guys, but I keep remembering things.

When I announced to him that the tech screening was over, he sighed and I could see 10yrs leave his face.  Come to think of it, that’s why I decided not to call him out in front of everybody and tell him he didn’t know anything… because I felt so incredibly sorry for him.  It’s like kicking a puppy until he bleeds and then laughing at him for the way he licks himself clean.

But he did ask the other team to take it easy on him because he just had a huge beating of a SQL interview.  He said that he had no idea we were going to ask him so many master-level questions, and then asked the guy how the job ad matched up with what we’re clearly expecting.

I’ll say that this whole thing is entertaining from the angle that I didn’t take him on to raise.  I’m not responsible for his knowledge or his income.  He’s clearly managed to find work all these yrs, so he’s gotta be doing something… right?  So I’m sometimes torn when I have interviews like this because I want to help these people… but I didn’t take them on to raise.  It’s not my job to teach them everything they need to know.  And while we’re feeling sorry for him let’s all remember that he’s got more time in this industry than I do and he’s chosen to not pick up any books or read any articles.  He’s chosen that himself.  So y, it’s sad that he’s that pathetic, but he brought this on himself.  I bet even dog catchers read dog catching books.

The big question is, does someone like that deserve our ridicule or our pity?  I say both really.