Bashar Kokash' Blog

.Net Framework, windows and web development.

This site

Resources

Friends

Sponsors

  • MaximumASP
  • Packet Sniffer

August 2009 - Posts

Moving to Windows 7 RTM

I have been using Windows 7 since its first beta version along with the RC one, actually the first time to see Windows 7 new cool features was at PDC 2008, of course I was concentrating on the development side that was presented by Scott Guthrie, all that previous time, I was using windows 7 just for testing on a machine that I use for development.

Well now after the Windows 7 RTM released was shipped I think I am ready to adopt it at all levels on all machines. Right now I use two machines at my small “Home Office” , this is were I do most of my development work, my personal laptop runs Windows Vista, and my work office PC runs Windows XP with a couple of Virtual PCs.

Well it started at my Home Office where I installed Widows 7 on a fresh clean machine, it was as easy as 1 2 3, but when upgrading from Windows Vista you might find some trouble, I haven't upgraded from Windows XP yet.

 

Anyway the following should be considered when Upgrading from Vista to Windows 7:

1 – Microsoft and I suggest to Use Windows 7 Upgrade Advisor Beta, it is a very good small utility that verifies that your PC is ready for Windows 7 (Hardware and Software).

2 – Install Windows Vista Service Pack 1 or Service Pack 2, or else you will not be able to upgrade and the only available option will be “Custom (Advanced)”, you can use it if you want a fresh new installation, the old Windows will be moved to folder “Windows.old”.

3 – According to Scott Hanselman: if you have .NET framework 4.0 and VS2010 Beta you should uninstall them before upgrading to Windows 7, then reinstall them again after a successful upgrade. More details here.

4 – I am not sure if this is the case for other anti-virus software, but apparently Windows 7 requires that you uninstall Kaspersky anti-virus, I Installed it after upgrading but apparently Windows 7 thinks that kaspersky will affect the system behaviors and performance so I installed an RC version of the Maintenance Plan 4 as a patch to Windows 7.

 

Related References:

- Windows 7 Home Page.

- Top 10 Tips Working Developers Should Know about Windows 7 by Scott Hanselman.

- Kaspersky Lab takes next step towards Windows 7 support

Removing duplicate data

Database duplicate rows and data are considered one of the biggest threats that face SQL developers. It may also affect the behaviors of applications that rely on that database the contains those duplicate rows, by providing mistaken data.

A SQL server database designer could solve this problem easily by using UNIQUE constrains or IDENTITY keys, that for sure will prevent adding records the may break any of those keys or constrains, but most of the times or let’s say sometimes, data could be obtained from different resources (for example a text file) where data could be uncertain,miss-typed, and/or not following rules and instructions, these sources may have no abilities to remove those duplicates, especially when large amounts of data are involved.

The solution is to import those data to SQL server as is using SQL Server Integrations Services, then check if it contain any duplicates and finally, process those duplicates (move or delete). The following is a practical example of how to  deal remove duplicate records using a cursor:

The input Data:

ID

FirstName

LastName

BirthDate

HiredDate

1 Ahmad Ali 1/1/1986 1/1/2005
1 Ahmad Ali 1/1/1986 1/1/2005
1 Ahmad Ali 1/1/1986 1/1/2005
2 Mohammad Ameen 2/2/1980 1/1/2004
2 Mohammad Ameen 2/2/1980 1/1/2004
3 Bashar Kokash 1/1/1986 3/5/2008
4 Asmaa Saeed 1/1/1987 1/1/2007
4 Asmaa Saeed 1/1/1987 1/1/2007
5 Morhaf Mosa 1/1/1983 1/1/2009

 

The T-SQL procedure:

CREATE PROCEDURE [dbo].[DELETEDUPLICATE]
AS
BEGIN

DECLARE @FIRSTNAME VARCHAR(50) ,
              @LASTNAME VARCHAR(50), 
              @COUNT INT,
              @BIRTHDATE DATETIME,
              @HIREDDATE DATETIME,
              @DELETEDROWS INT


SET        @DELETEDROWS = 0

DECLARE C_EMPLOYEE CURSOR FOR
    SELECT
FIRSTNAME,LASTNAME, BIRTHDATE,HIREDDATE,COUNT(*)
    FROM EMPLOYEE
    GROUP BY FIRSTNAME,LASTNAME, BIRTHDATE,HIREDDATE
    HAVING COUNT(*)>1 –This select statement gets only duplicate rows

OPEN C_EMPLOYEE

FETCH NEXT FROM C_EMPLOYEE INTO
    @FIRSTNAME ,@LASTNAME ,@BIRTHDATE ,@HIREDDATE ,@COUNT

WHILE @@FETCH_STATUS =0
BEGIN

DELETE TOP (@COUNT-1) – if there is 5 copies of a record then delete 4 and leave one
    FROM         EMPLOYEE
    WHERE        FIRSTNAME    = @FIRSTNAME
            AND LASTNAME    = @LASTNAME
            AND BIRTHDATE    = @BIRTHDATE
            AND HIREDDATE    = @HIREDDATE

SET @DELETEDROWS = @DELETEDROWS + @@ROWCOUNT
– gets the number of rows deleted


FETCH NEXT FROM C_EMPLOYEE INTO
    @FIRSTNAME ,@LASTNAME ,@BIRTHDATE ,@HIREDDATE ,@COUNT

END


CLOSE
C_EMPLOYEE
DEALLOCATE C_EMPLOYEE

RETURN @DELETEDROWS
END

The output data:

ID FirstName LastName BirthDate HiredDate
1 Ahmad Ali 1/1/1986 1/1/2005
2 Mohammad Ameen 2/2/1980 1/1/2004
3 Bashar Kokash 1/1/1986 3/5/2008
4 Asmaa Saeed 1/1/1987 1/1/2007
5 Morhaf Mosa 1/1/1983 1/1/2009

 

The Result:

Now as a result we have a new unique copy of the same duplicate data with a little effort, that may save time and cost if duplicates were not processed