Tag: syndicated

  • Office Work

    rg_buildingI have been working at home for over 8 years, sharing an office with my wife for most of that time. I like working at home, though I do notice that if my wife is gone for a few days, I go a little stir crazy being completely by myself. It’s almost “too quiet” for me and I end up sometimes going to a Starbucks to work, just to have some ambient noise.

    This week I’m in the UK, visiting with my group at Red Gate Software. Typically I spend a few days in a conference room with my group and then a day or two in the office. Today is an office day, and it’s amazing just how busy and crowded the Red Gate spaces have become.

    You can see the Red Gate building here, two wings, with the upper two floors being completely Red Gate space. When I came last year, the quadrant where my group is located was fairly empty. Now it’s quite full, with most desks in use.

    rgoffice

    Most of the space is busy, and the lunch service from the in house cafeteria is very busy. It was so busy I forgot to get a picture before eating, being slightly worried about getting my own food and finding a seat. I went back near the end of lunch and snapped this one:

    lunch

     

    The SQL Servery, as it’s known, was just getting going before, but now it’s in full swing, with the menu’s posted, and lots of choices. Yesterday I had a lamb ragout and today was a spicy pasta vegetarian dish instead of the bangers and mash (shudder). Juices of all sorts are around, along with the most important piece of technology in the office:

    coffee

    I have made liberal use of this machine in the two days I’ve been in the office. The food is mostly healthy, which is good to see. At first I was a little put off that the only sodas in the office are in a vending machine, requiring all sorts of strange UK coins, but on this visit I’ve rarely had a soda all week and it’s been fine. I think if I had a company these days I’d consider providing healthy snacks and drinks for free and letting people buy the unhealthy stuff if they want.

    minimeMy “mini-me” is still there, which is cool. I thought this was one of the coolest pieces of art produced by the Red Gate designers. When I first saw it, I thought it was great. There are a few other walls that are decorated with various paintings and drawings.

    The office is bright and airy, and surprisingly quiet given all the people there.

    But there’s lots of them, more than I’m used to, so it’s a bit strange to walk around to get water or coffee and dodge people. Usually I’m just dodging a dog or two.

    One other very interesting thing is the memory wall. A long wall, with some cork sections, and some metal sections, where people post photos from company events and various press articles. It seems there are regular Red Gate events (which I rarely get to) that build bonds and help keep the company close together. I need to send something over to place up there.

    memory_wall

    I’m not much of a foosball player, but I see games going on regularly in the lower lobby area. There is a ping pong table, and it makes me think I need to get mine set up in the basement back at the ranch.

    Not much work getting done this week, but it’s a good trip and good to see so many of the people I correspond with on a regular basis and others I’ve known for years.

  • Striping Backups in SQL Backup Pro

    SQL_68x68_BackupThere are times you really do want to stripe backups across multiple files. If you have a short backup window, or a large data set, if you can write the backup to multiple files at the same time, you can drastically reduce your backup window. I think I heard one person say they had a client that was backing up a 2TB database in around 30 minutes with striping. Now that’s cooking with gas!

    My company, Red Gate Software, makes a nice backup product called SQL Backup Pro, which offers a number of features, compression and encryption being the two most notable ones. However I noticed at one point that it supported striping as well, so I decided to play with it.

    I started the backups, picking a database and then getting to the backup file screen.

    sqlbackup1

    There’s a drop down in the upper left, which gives you a few choices. One of these is the backup and mirror and the other is a backup to multiple files.

    sqlbackup2

    I selected the “Split backup into multiple files”, which equates to striping, and then added a file to the file dialog.

    sqlbackup3

    However I wanted to add a second file. I clicked “Add” again.

    sqlbackup4

    It’s nice that the names are changed, but adding a second file to the same path isn’t likely to give me much more throughput on the backup. Both files would write to the same I/O device. I was thinking that “Add” might give me a dialog for a different drive/path, but it didn’t.

    Instead I needed to click on the ellipsis next to the folder (I’ve added the arrow in the image below):

    sqlbackup5

    This brought me to a dialog that shows me the drives my machine can see. I didn’t test UNC paths, but I assume any valid path would work. You can set a path, or you can pick one, and you can even create a new folder. Handy since this could be a remote machine. The SQL Backup Pro client is like SSMS, it’s a client view to a remote service.

    sqlbackup6

    I select the D: drive on my machine, which is actually a separate physical drive.

    sqlbackup7

    I get back to the main dialog, and this time when I click “Add”, I get the desired result. A second file on a different path.

    sqlbackup8

    I run the backup, and sure enough, I have files in two places, each a little over 1MB. There’s some overhead, so it’s not a completely even stripe.

    sqlbackup10

    sqlbackup11

    As a comparison, I’ve highlighted a regular backup I made after this, same db, with one file:

    sqlbackup9

    That seems a little cumbersome, but I’d anticipate that you would only set this up once for each set up databases, and since you can easily script a SQL Backup set of commands (on the last screen) or create template, this shouldn’t be too hard to manage. In fact, the command for multiple databases does support striping as well, as in this example:

    EXECUTE master..sqlbackup ‘-SQL “BACKUP DATABASES [AdventureWorks,AdventureWorks_SSC,AdventureWorks2008R2]

    TO DISK = ”F:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Backup\<AUTO>_2.sqb”,

    DISK = ”C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Backup\<AUTO>_1.sqb”

    WITH DISKRETRYINTERVAL = 30, DISKRETRYCOUNT = 10″‘

    Since striping is usually done with only very large databases, this might not even be necessary. Most databases won’t need striping, and you can set a template for them that backs up to whatever location you wish.

    SQL Backup Pro has some nice features, and allows you to easily manage lots of backups across lots of servers. The compression ratios are nice and it has some great features, like this striping of backups, that can really improve your backup performance.

  • The IF Statement in a T-SQL Query

    I’ve seen quite a few posts from people asking how to do something like this:

    SELECT 
      a.ID
    , IF a.MyChar = 'A' THEN 'Success'
      ELSE 'Fail'
    FROM MyTable a

    Of course, that doesn’t work in T-SQL, and you’ll get something like this:

    Msg 156, Level 15, State 1, Line 3

    Incorrect syntax near the keyword ‘IF’.

    Msg 156, Level 15, State 1, Line 3

    Incorrect syntax near the keyword ‘THEN’.

    There’s not IIF, no IF( x, then y, else z) construct. There is an IF … ELSE statement, but it’s use in code flows as a control statement such as

    DECLARE @i CHAR(1)
    SELECT @i = mychar FROM MyTable
    
    IF @i = 'A'
      SELECT 'Success'
    ELSE 
      SELECT 'Fail'
      

    Instead we have a CASE statement, which is designed to give you multiple choices. In the example above, I’d write:

    SELECT 
      a.ID
    , CASE WHEN a.MyChar = 'A' THEN 'Success'
      ELSE 'Fail'
      END
    FROM MyTable a

    I can even add multiple “WHEN” clauses if I want:

    SELECT 
      a.ID
    , CASE 
        WHEN a.MyChar = 'A' THEN 'Success'
        WHEN a.MyChar = 'B' THEN 'Close'
        WHEN a.MyChar = 'C' THEN 'Far'
        ELSE 'Fail'
      END
    FROM MyTable a

    Let your developers know that when they are looking for an inline IF type of logical statement, T-SQL gives them CASE instead.

  • Recovering a Database

    So you’re restored a database, restored a few logs, all with NORECOVERY as expected and realize there are no more logs. You see this in Management Studio and wonder what do to:

    restoringdb

    I’ve run a bunch of code, restoring lots of files, but I’m done.

    RESTORE DATABASE db4 FROM DISK = 'db4_base.bak' WITH norecovery
    RESTORE LOG db4 FROM DISK = 'db4_log1.trn' WITH norecovery
    RESTORE LOG db4 FROM DISK = 'db4_log2.trn' WITH norecovery
    RESTORE LOG db4 FROM DISK = 'db4_log3.trn' WITH norecovery
    RESTORE LOG db4 FROM DISK = 'db4_log4.trn' WITH norecovery
    ....
    RESTORE LOG db4 FROM DISK = 'db4_log42.trn' WITH norecovery
    

    You don’t need another log to bring things online. This simple command will fix things:

    RESTORE DATABASE db4 WITH recovery
    

    That will return:

    RESTORE DATABASE successfully processed 0 pages in 2.629 seconds (0.000 MB/sec).

    and your database will be ready to go:

    retoreddb