Importing Data to SQL Server

I was recently asked to help a client migrate some data from IBM DB2 to SQL Server.

It was about 900 tables and a couple of terabytes of data. Before I came onsite, the client had extracted the data from DB2, a process which alone took a couple of days.

Was I was presented with was the following: one file for each table containing INSERT INTO statements for each row to be inserted into SQL. The largest file was about 2 GB, the smallest one a few K. Due to time constraints it was not possible to re-extract the data into a format there e.g. BULK INSERT or SSMI could be used.

The client had tried to import one of the larger ones – around 1.3 GB with about 3.2 million lines – using the command utility OSQL. After 14 hours we stopped the process.

My first thought was to insert explicit transactions into the files getting a structure of something like this:

BEGIN TRANSACTION
INSERT INTO …

INSERT INTO …
COMMIT TRANSACTION

I wrote a small utility which would transform the original files into the above structure given the overall size of the file and maximum allowed batch size, e.g. lines in each transaction.

This did not really help at all. The aforementioned file still took ages.

As we were running out of time, a request was made to upgrade the SQL server from 2 to 4 cores and to 16 GB Ram. This of course did not solve our import problem, but at least we got some more juice to play with.

I next made two changes, which turned out to solve the problem:

  1. Used SQLCMD instead of OSQL
  2. Split input files up into smaller chunks

SQLCMD was introduces with SQL Server 2005. It is using OLE DB and not ODBC for connectivity and it is 64 bit. Both of these will of course speed up performance.

To split up the files into smaller chunks I found a small utility called TextFileSplitter. The utility is free to use and comes with both a UI and command line interface.

Writing a small CMD-files automated the process of splitting up the largest files into chunks of 100K lines each.

SET INPUT=C:\Input
SET OUTPUT=C:\Output
SET LINES=100000

FOR %%F IN (%INPUT%\*.*) DO TextFileSplitterConsole -i=%%F -o=%OUTPUT% -splitstrategy:ls:%LINES%

 

Once we had the smaller files I started three other “CMD-file processes” to execute all the INSERT INTO statements using SQLCMD.

All in all it took a couple of hours for the splitting and inserting of data.

End result: happy client.

Posted in Tips | Tagged | Comments Off on Importing Data to SQL Server

Tech Ready 12

I’m at TechReady this week, an internal Microsoft conference.

Tons of sessions and people to meet.

Posted from WordPress for Windows Phone

Posted in Conference | Comments Off on Tech Ready 12

College Statistics

Michael Feathers (@mfeathers) posted a link on twitter to a nice little statistics assignment.

If you would like to solve it yourselves, stop reading when you get to the mathematics, otherwise it will spoil your fun.

Enjoy 🙂


Currently a college senior, Jeremy has had a secret crush on Emma ever since the third grade. Two weeks ago, fearing that his feelings would forever go unrequited, he broke his silence and sent Emma a letter through Campus Mail, acknowledging his twelve/year secret romance.Now, fourteen agonizing days later, he has yet to receive a response. Hoping against hope, Jeremy and his fragile psyche are clinging to the possibility that someone’s letter was lost in the mail.

Assuming that:

  1. Emma (who is actually secretly dating Jeremy’s father) has a 70% change of mailing a response if, in face, she had received the letter and
  2. The Campus Post Office has a one in fifty change of losing any particular piece of mail,

what is the probability that Emma never received Jeremy’s confession of the heart?

Let B represent the event that Jeremy did not receive a response; let A_1 and A_2 denote the events that Emma did and did not, respectively, receive, Jeremy’s letter. The objective is to find P(A_2 | B).


Stop reading now, if you do not wish to see the proof. Not that it is very complicated, mind you, but try to extract that old knowledge from years back when you had statistics yourself.

From what we know about Emma’s behavior and the incompetence of the Campus Post Office,

\displaystyle{P(A_1) = \frac{49}{50}, P(A_2) = \frac{1}{50}, P(B | A_2) = 1}

Also,

\displaystyle{P(B | A1) = P(\mbox{Jeremy receive no response} | \mbox{Emma received Jeremy's letter})}

\displaystyle{ = P[\mbox{Emma does not respond} \cup (\mbox{Emma responds} \cap \mbox{Post Office loses letter})]}

\displaystyle{ = P(\mbox{Emma does not respond}) + P(\mbox{letter is lost} | \mbox{Emma responds}) \times P(\mbox{Emma responds})}

\displaystyle{ = 0.30 + 0.70\frac{1}{50}}

\displaystyle{ = 0.314}

Therefore,

\displaystyle{ P(A_2 | B) = \frac{1\frac{1}{50}}{0.324\frac{49}{50} + 1\frac{1}{50}}}

\displaystyle{ = 0.061}


Sadly, the magnitude of P(A_2 | B) is not good news for Jeremy. If P(A_2 | B) = 0.061, it follows that Emma’s probability of having received the letter but not caring enough to respond was almost 94\%. “Faint heart ne’er won fair lady,” but Jeremy would probaly be well/advised to direct his romantic intentions elsewhere.

Posted in Writing | Tagged , | Comments Off on College Statistics

TechReady and MSSU

In February I will be attend two Microsoft conferences, TechReady and MSSU, in Seattle and Redmond.

The first is the internal TechEd. I am really looking forward to the opportunity to hear a lot of great session about all the cool technology.

The second, MSSU, is a week of Microsoft 1-0-1, brain washing, indoctrination, call it what you want. I am going to learn to do it “The Microsoft Way”.

An added benefit will be, that I get go spend a little time with my sister, brother-in-law and nephew.

Posted in Conference | Tagged | Comments Off on TechReady and MSSU

Windows Phone 7

The following ramblings concern my first impressions on my new cell phone. Before starting at Microsoft I was told, that all employees would be given a new Windows Phone 7. Unfortunately they were in short supply here in Denmark, so I got an old HTC brick and only recently got the real one: a HTC Mozart.

A confession: privately I own an iPhone and I love it. It it the first time I have had a phone, where I did not want another one after 14 days, because it had the wrong form factor or was lacking some kind of functionality or I tried really hard to convince myself that it was a great phone, because it had cost me a lot of money.

I have had windows phones before, and let us be honest: they did not work. In the best cases, you only had to cold start it four times a day and was actually able to pick up most of your incoming calls. And that was on the better days.

My first impressions of the Mozart are good. It has a nice form factor and feels good in the pocket and hand. It is very responsive and the user interface is quite intuitive. I’ve got myself an American LiveID, and tried to install a few apps from the market place. Worked without any problems. It is going to take some time to find out which apps to use, but that is to be expected on a new device.

I have not had time to try the music player yet, but look forward to this part as well, as I currently travel around with two devices, as my iPhone still holds my music, audio books and podcasts.

I am missing a few features like being able to install your own ring-tone and using the phone as a modem, but this will hopefully be added in a future software update.

Conclusion: Even though I am missing a few features, I feel the HTC Mozart running Windows Phone 7 will be a nice replacement for my iPhone, as I doubt I will care to carry two devices around forever.

Posted in Windows Phone 7 | Tagged , | Comments Off on Windows Phone 7

Merry Christmas

Dear Friends and Family,

 

The best wishes for the holiday season and the new year.

 

Posted in Private | Tagged | Comments Off on Merry Christmas

My new coffee grinder

I gave myself an early christmas present this year or to be completely honest, my wife told me, that I had just done so, when I told her, that I had bought “us” a Mahlkönig Vario coffee grinder.

I have previously written about my love of coffee and my dream of someday getting a proper espresso machine. If you want to make a good espresso, you basically need two items: the espresso machine itself and a grinder. I guess I’m half way now.

What espresso machine should it be then? When I inherit or win in Lotto I would still consider to buy the one group Linea or the GS/3 from La Marzocco in Florence or even better the Cyncra from Synesso in Seattle. As this is not likely to happen, the Vibiemme Domobar Junior in the dual boiler configuration is more within my reach and it has a really nice form factor, well suited for a private kitchen.

Posted in Cooking, Private | Tagged | Comments Off on My new coffee grinder

And the winner is …

Først en tak til alle dem, der har sendt svar ind på spørgsmålene fra i går.

Knap 50 havde taget udfordringen op og langt de fleste har svaret rigtigt. Håber ikke, at det var for let? Jeg kan se, at Google ikke har levet forgæves 🙂

Svarene på de 5 spørgsmål er:

  1. Hvad er følgende sætning et eksempel på? Du, Egil, Åge lo, da Baronesse Nora bad Ole gå lige ud.
    Svar: Palindrom
  2. Hvilken bog starter således: The sky above the port was the color of television tuned to a dead channel.
    Svar: Neuromancer af William Gibson
  3. Hvornår stiftede man første gang bekendskab med Arthur Dent og Fort Prefect?
    Svar: 1978 (radioshow hos BBC)
  4. Hvad var GIER og hvorledes adskiller denne sig fra sin “forgænger”?
    Svar: Den første danskbyggede transistorbaserede computer/regnemaskine. Forgængeren (DASK) brugte radiorør.
  5. Vi befinder os i det hellige år 11B6 AD, hvis vi i stedet for base10, brugte?
    Svar: base12

And the winner is: Jørn Schou-Rode.

Posted in Christmas | Tagged | Comments Off on And the winner is …

Hr. Frosts julekalender

Velkommen til endnu en låge af Hr. Frosts julekalender.

For nu, at det ikke skal være kode det hele, har jeg sammensat et par enkelte spørgsmål, som enhvert nørd – med respekt for sig selv – burde kunne svare på.

Send svar til mig på karsten at strobaek.dk inden midnat; vinderen bliver offentliggjort i morgen og vil blive den lykkelige ejer af følgende to gadgets: et LED Binary Watch og en cool t-shirt.

  1. Hvad er følgende sætning et eksempel på? Du, Egil, Åge lo, da Baronesse Nora bad Ole gå lige ud.
  2. Hvilken bog starter således: The sky above the port was the color of television tuned to a dead channel.
  3. Hvornår stiftede man første gang bekendskab med Arthur Dent og Fort Prefect?
  4. Hvad var GIER og hvorledes adskiller denne sig fra sin “forgænger”?
  5. Vi befinder os i det hellige år 11B6 AD, hvis vi i stedet for base10, brugte?



God fornøjelse.

Posted in Christmas | Tagged | 1 Comment

How difficult can it be?

I really enjoy logical and mathematical problems, so when I came across the “world’s hardest easy geometry problem” I was quite excited. I mean, how difficult can it be, right? 180 degree in a triangle and you are set.

I dare anyone to try and solve the problem below: find the angle x. Sure you can measure the angle, but that is cheating. Grab pen and paper and let me see your “proof”; I would be very interested in comparing notes. I spend many hours for many days solving this, but then again, I’m not the sharpest knife in the draw.

World's Hardest Easy Geometry Problem

Update: I forgot to write, that you are only allowed to use simple geometry. No trigonometry is allowed.

Posted in Miscellaneous | Tagged | Comments Off on How difficult can it be?