We all use COUNT() to count the total records in a table.But there are few facts we all unknowingly ignore.

In the example below I have use COUNT(*), COUNT([tableField]) and COUNT(1)

COUNT(*) does return the count of all the records, BUT takes lot of memory and time when we have a big table with huge data.

COUNT([tableField]) does return the count but when the field has NULL as data value the,it escapes to count those records because the field is NULL.
So always use the Key column.

Here 1 = the first column of the table-key column which is always the key column of any table
1) It takes into account the NULL value.
2) It saves time and memory.

Create table tblCountTest
( fldCountryName varchar(10));

insert into tblCountTest values (‘Nepal’);
insert into tblCountTest values (‘China’)
insert into tblCountTest values (NULL);
insert into tblCountTest values (”);
insert into tblCountTest values (‘Cambodia’);
insert into tblCountTest values (NULL);
insert into tblCountTest values (‘Japan’);
insert into tblCountTest values (‘Brazil’);

select * from tblCountTest
select COUNT(*) as recordCount FROM tblCountTest; — shows recordCount = 8
select COUNT(fldCountryName) as recordCount FROM tblCountTest; — shows recordCount = 6
select COUNT(1) as recordCount FROM tblCountTest; — shows recordCount = 8
Happy Coding 🙂


I dont feel safe

I just got a notification from google “Google Terms of Service Updated” and I am having an mini anxiety attack.I am wondering who will be scrutinizing my information, my emails, my stuffs, how will the data be used, abused and sold and resold.I wish I could declare,ok I wont use this thing called internet,I will shut down everything.Even-if I decide to,I am already on (their) data-centers,a considerable amount of me is already with them.And I cannot tell them I don’t want to use you please spare me.

I am all scattered in web, part of me lies in facebook other half on twitter and I am tits and bits all over in different social networking sites.A chunk of me lies in sugarsync,dropbox,where not.Yes I don’t feel secure, there are cloud servers I use, I have had synced me with them, my personnel belongings, professional journals, my secret indulgings what not.Yes I am scattered everywhere.I so am floating in fearful concern of my interest,Phew!!

I have been having this feeling way before Mr Snowden leaked Prism.I sometimes wonder if using TOR or disconnect will save me from being crawled and tracked to some extent. Again I question Would not these so called anti surveillance or anti tracking companies use my informations.Would not it be same in one way or other?I let other bunch of them use me, just in different way.

when I read about the Silk Road, it was so intriguing;I wondered how things worked and fantacise of building something similar.Wont it be amazing to have something of my own: no surveillance, no crawling, no bots, a world of my own, where my data would be safe and not employed for filling up other’s pocket

Nothing is for free I get it,so this is the sum amount I need to pay for using things for free but isn’t this amount we are paying a bit too much? I am solding myself off to get a bar of candy for free.This is an abuse.We are being abused and this has lead each one of us to live in threat, each single moment. Some dignitaries live in fear-fear of being public,affairs being barefaced.And a normal person like me fear of being tagged as a republican or supporter of Mao ,Zeehad or anything, on basis of the conversations I make on instant messaging or my emails or social media activities which is absurd.I like Manchester United.Will that make me a anti Chelsea supporter when I am teasing my friend with anti Chlesea slogans?

I think we all need to wake up and start thinking about these issues.

How can we live like this?

This is against my rights to security, rights to liberty,my rights to live a life.

Fix the Reseeds

To reseed the tables in SQL server 2012 identity column getting incremented by 1000 after fail over or restart

create procedure spFixReseed
declare @MAX int
select @MAX = max(Identity_Col) from DBName.dbo.Table

sp_procoption @ProcName = ‘spFixReseed’ , @OptionName = ‘startup’ , @OptionValue = ‘true’

After the restart the seed will be reset correctly.