Thursday, July 28, 2011

Conditional insert query without duplicates

This is just a sql puzzle which raised during a long wait for the QA results on a build day.The puzzle seems simple.

  1. Need to insert the records with out duplicates.
  2. The query should consider all the fields.
  3. The query should be single single statement of query execution.

At first it feels simple as a simple where query. But when we start writing we realize that can we write a where clause in a insert query? Simply speaking how can we write a conditional insert query in sql.After we play with the sql server and queries we automatically come to the below query.

INSERT INTO Person (Name , EMail,Id) 
select 'joy', '',1
FROM Person
WHERE Name = 'joy' and email='' and id=1) = 0;

The table can be created using.

CREATE TABLE [dbo].[Person](
[Name] [nchar](50) NULL,
[Id] int NOT NULL,
[EMail] [nchar](50) NULL)

Wednesday, July 20, 2011

ILSpy another replacement for Reflector
Another reflector alternative like Telerik's Just Decompile

According to the ILSpy team..Development started after Red Gate announced that the free version of .NET Reflector would cease to exist by end of February 2011.

Sunday, July 17, 2011

Goto statement used in .net framework

From the very beginning of the C,C++ and C# days it was told that using goto keyword is not a good practice .Most of the developers are following the same too.They spent little more time in their C# career starting time to avoid goto statements if they are from goto programming world.

But today I happened to see a goto statement not really couple of goto statements in the .net framework. Actually I was searching for a mechanism to parse a string of sql statement and create select command out of that.So obviously I entered in the SQLCommandBuilder class and started reflecting the GetUpdateCommand.After digging into inner methods I saw couple of goto keywords in a private method of DBCommandBuilder.BuildUpdateCommand. Can't you believe? See the below screen shot. I am using .net 3.5.So the framework version shows 2.0.

Is it the problem of reflector disassembling the IL? Or written as it is. Who knows...

Tuesday, July 5, 2011

Process monitor for monitoring who is doing what

Recently I came to see a wonderful tool for monitoring the activities inside our system. Almost everybody may knows it which is nothing but the ProcessMonitor from Microsoft. I happened to use this while dealing with deadlocks in our application .It seems there are so many use cases with this tool such as you can monitor unknown processes if those are of virus kind,why your system hard disk is getting full etc...

For me its useful to find out what are the processes using files for reading or writing at a given point of time.Also we can watch if the registry is being modified by any process.