Wednesday, November 14, 2007

While we're waiting for the next SQL Server CTP, it thought I could mention a couple of small things already in the current CTP: Multiple row Insert and Declare-Set combined.

To insert multiple rows  in SQL Server 2005 and before, you had to execute multiple INSERT statements, or use UNION. The first would look like this:

INSERT INTO MyTable (Col1, Col2)
VALUES (1, 'One') INSERT INTO MyTable (Col1, Col2)
VALUES (2, 'Two') INSERT INTO MyTable (Col1, Col2)
VALUES (3, 'Three')

And using UNION it would be

INSERT INTO MyTable (Col1, Col2)
          SELECT 1, 'One'
UNION ALL SELECT 2, 'Two'
UNION ALL SELECT 3, 'Three'

In SQL Server 2008, this can be done like this:

INSERT INTO MyTable (Col1, Col2)
VALUES (1, 'One'), (2, 'Two'), (3, 'Three')

I did some quick performance testing and found that UNION and multiple inserts runs on about the same time, while the single inserts are slower. But this is only true as long as the numbers of rows being inserted isn't to high. If inserting 10 000 rows in one go, for instance, the individual inserts are actually faster, probably because of the amount of in-memory data the unions and the multiple row inserts produce, as well as that the last two commands run the whole batch within on large transaction.

Then, Declare-Set combined: It has long irritated me that I had to use two lines to declare a variable and assign a value to it. This is what it looks like i SQL Server 2005 and earlier:

DECLARE @var int
SET @var = 50

Now, in SQL 2008, we can do this:

DECLARE @var int = 50

We can also declare and assign to multiple variables in one go:

DECLARE @var1 int         = 50,
        @var2 varchar(10) = 'Hello!'

Pretty basic, and it's probably long overdue, but it's neat and it's finally here :-)

posted on Wednesday, November 14, 2007 5:06:28 AM (W. Europe Standard Time, UTC+01:00)  #    Comments [0]
 Tuesday, November 13, 2007

Microsoft Norway is running a gadget competition at http://www.gadgetcompetition.no/ these days where users can submit Vista Sidebar Gadgets and Windows Live Gadgets.

My contribution is a Vista Sidebar gadget where you can track packages and letters sent via the Norwegian Postal service, Posten. By entering you package tracking number, the gadget will get the latest updates for you package every 30 minutes and display its status in the sidebar. You can also click the envelope to open up the full package history in a fly out window.

So, if you like the idea, go to the competition site, and download my gadget from the "Gadget Gallery", or use this direct link to live.com. If you like it, please log in with your Windows Live account on www.gadgetcompetition.no and vote for me :-) You can win Vista Ultimate, a mouse or Expression Web just by voting :-)

posted on Tuesday, November 13, 2007 2:10:00 AM (W. Europe Standard Time, UTC+01:00)  #    Comments [3]
 Sunday, November 4, 2007

I've spent some time thinking about what factors determine exam results. It clearly depends upon the amount of effort you put into it (and the preparations) and your skill level, but also how lucky you are with the tasks you get on the exam. I think I've come up with a mathematical relationship for it :-)

Result = Effort x Skills x Fluke

That is, the exam result is the product of effort, skills and how lucky you are. Here, all factors are non-negative, which gives us a non-negative result as well. A result of zero is a fail, anything above that is a pass.

As we can see, if any of the three factors are zero, you will fail. This is easy to explain. First, if the effort is zero, you didn't even bother showing up on the exam, so you will clearly fail. Further on, if you have zero skills, you don't even know how to read, yet alone remember anything, so no matter how much effort you put into it, you will still fail. Finally, a zero luck means maximum bad luck. An example of this could be to get the following exam:

Task 1 of 1: (100 %)
Is P = NP? Prove your answer.

We can also get some more interesting relationships out of the formula. By dividing by Effort on both sides, we get
Result / Effort = Skills x Fluke.

This tells us that, if you got a non-failing grade on the exam, while the effort approaches zero, you either have extreme skills, or you had a huge amount of luck.

We can also get Result / Skills = Effort x Fluke. So if you got a passing grade, and have zero skills, you put in impossible amounts of effort, or had impossible amounts of luck, which is just not possible, so you could not possibly pass the exam.

So, by using this formula, you should be able to develop a strategy for receiving good exam results ;-) Good luck!

posted on Sunday, November 4, 2007 5:59:20 PM (W. Europe Standard Time, UTC+01:00)  #    Comments [3]
 Tuesday, October 30, 2007

...does not work, it looks like.

I upgraded my installation (hosting this site) of Windows Server 2008 from Beta 3 (June CTP) to RC0 today - over remote desktop! My server is located in a locked server room, so I wanted to try a remote upgrade before asking for the key, and it went well. I extracted the ISO onto the hard drive, started the installation from remote desktop and selected the upgrade option. It turns out that the Windows setup doesn't (luckily) show any dialogs where you have to click next during the upgrade. I had a continuous ping trace running and observed the server going up and down a few times, before it completed the installation and enabled incoming remote desktop connections again. Pretty cool!

But, back to the title. Everything worked well after the upgrade, except SQL Server 2008 July CTP. I kept getting error messages from Management Studio when connecting saying "No process is on the other end of pipe", and this led me into thinking that I had a certificate problem. See this blog post.

But, it turns out that this wasn't the issue. The issue is that Windows Server 2008 RC0 ships with a version of SQL Native Client that is newer than what the SQL Server 2008 July CTP supports, so it just doesn't work. This thread says it will be addressed in the next SQL Server CTP. Until then you have two options:

  • Use Management Studio 2008 from another machine to administer SQL Server. This will probably still give you problems if you run SharePoint on the same server, at least my SharePoint installation gets the "No process in end of pipe"-error
  • Install SQL Server 2005

For now, I'm going with SQL Server 2005 while I'm waiting for the next CTP of SQL Server 2008. I read somewhere that it is expected in the next one to two weeks. It will probably contain lots of new stuff, like spatial data support, Intellisense in Management Studio and so on. Looking forward to it!

posted on Tuesday, October 30, 2007 6:37:16 PM (W. Europe Standard Time, UTC+01:00)  #    Comments [0]
 Monday, July 23, 2007

It's been a while since my last blog post, so now could be a good time for some updates. First; I'm back in Redmond this summer too, in a summer internship for Microsoft. I'm working on the SQL Server team this year too, but changed teams internally, from the Test Execution Team to the SQL Server Build Team, which is responsible for building (compile, optimize, sign etc.) SQL Server. This means that I design and write software we use to build SQL Server. Right now, I'm working on a system for Peer-to-Peer File Sharing in the build lab, in C#. Building SQL Server involves copying hundreds of GB of data over the lab network, so by doing this p2p instead of centralized, we can reduce the load on the network. This project is really challenging and fun to work on.SQLserver05Ent_web.jpg

So, what about the title of this blog post? This Thursday, all interns were invited to a lecture by J. Allard, and the e-mail said that they would be doing a raffle drawing for one Zune for all the interns after the lecture, but instead they gave away a free Zune for every single one of us! Pretty cool!

I haven't used it too much yet, but so far it looks very good. With it came a 14 day Zune subscription pass, which enables you to download most songs from the Zune on line store for free, which is pretty cool.

I plan to write a few blog posts about how you get an internship at Microsoft, and what it is like, so stay tuned :-)

Below is a picture of a part of the main campus with building 35, where I work, highlighted:

campus_aerial_3_web.jpg

posted on Monday, July 23, 2007 12:28:03 AM (W. Europe Standard Time, UTC+01:00)  #    Comments [0]
 Thursday, May 17, 2007

I am studying for my exam in Performance Engineering these days, and came across a nice way of estimating Pi in the chapter about Monte Carlo simulations (random number simulations) yesterday. The idea is that you use random numbers to estimate something, in this case the number Pi.

Let's take a look at the figure below. Here we have the unit circle (a circle with radius 1 and center in origo) drawn in a coordinate system. Up to the right, in the first quadrant, I have shaded a square area with sides of length 1.

circle.png

As you probably should remember from school, the area of a circle is A = Pi * r^2, and this circle therefore has an area of A = Pi * 1^2 = Pi. One fourth of the circle is in the shaded area, and this part of the circle therefore has the area Pi / 4. The shaded area itself has an area of 1 * 1 = 1. Then we define R to be the ratio between the area of the shaded part of the circle and the whole shaded area. This ratio is R = (Pi / 4) / 1 = Pi / 4.

Now, let's imagine throwing darts at the shaded area at random (we do not aim for any specific area). Of all the darts hitting the shaded area, a ratio of them, corresponding to R (since there is equal probability for hitting any part of the square), should hit inside the circle. For instance, if the ratio is 0.7, and 10 darts hit the shaded area, 7 should hit inside the shaded part of the circle.

If we throw a fair amount of darts, we should be able to calculate R using the formula R = DartsInsideGreyCircle / TotalDartsInsideGreyArea. As we have from the paragraph above, R = Pi / 4, which means that Pi = R * 4. We have estimated Pi!

The JavaScript simulation below illustrates this. Click start and watch what happens! If you let it run for a while, the result will actually get quite close to the actual value of Pi.

Coordinates: (x, y) = (0, 0)
Hits inside: 0, hits outside: 0
Ratio: R = HitsInside / (HitsInside + HitsOutside) = 0.
Estimated Pi value: π ≈ 4 * R = 0.
Speed: 1 /s.
Note: If you are reading this through an RSS feed, you may need to open the blog post in a browser to be able to run it.
posted on Wednesday, May 16, 2007 11:26:07 PM (W. Europe Standard Time, UTC+01:00)  #    Comments [0]
 Monday, March 19, 2007

As many others, I also have a voicemail message box for my cell phone number that the caller gets redirected to if I don't answer the phone in something like 15 seconds. What I've found is that 15 seconds is a pretty short time when the phone is ringing and you need to find out where it is. It is OK if you're sitting right next to it, but if it is in some jacket lying somewhere around you're very likely to miss the call.

Therefore I called my phone company (Telenor) today to find out if it is possible to increase this timeout. I got a rather interesting answer:
Dial **61*<Your Voicemail Number>**<Timeout in seconds># on your phone, and you're done.

I don't know if it works only for Telenor customers, but it's worth a try :-) I also found that on my Windows Mobile phone I can actually change this setting under Settings --> Phone --> Services --> Call Forwarding, so that's maybe a more general solution.

So now I've got 25 seconds to find my phone when it rings :-)

 

posted on Monday, March 19, 2007 1:19:15 AM (W. Europe Standard Time, UTC+01:00)  #    Comments [2]
 Wednesday, February 7, 2007

During Christmas I took two upgrade exams (70-431: MS SQL 2005 Imp&Maint, 70-553: MCSD to MCPD Part 1) to upgrade my Visual Studio 2003 and SQL Server 2000 certifications to .NET Framework 2.0 and SQL Server 2005. Those combined with two I took in Redmond last summer (70-447: MCDBA to MCITP:DBA, 70-554: MCSD to MCPD Part 2) gave me a bunch of new certifications all at once, more precisely 4 x MCTS, MCITP: DBA and MCPD: Ent.App.Dev.

Then the interesting part: All of those come with welcome kits with diplomas, some also with pins and wallet cards in separate envelopes. Therefore, I was wondering if they were going to put everything in one envelope when I ordered something like 9 welcome kits at once. But they didn't, and here the other day I found my mailbox full of welcome kits :-) Take a look at the picture below where I have spread them out on the bed.

welcomekits.jpg

posted on Wednesday, February 7, 2007 1:59:59 AM (W. Europe Standard Time, UTC+01:00)  #    Comments [8]