Overblog Follow this blog
Administration Create my blog
Balavardhan Reddy Narani

Artcal about Mind & Soul

December 17 2009 , Written by Balavardhan Reddy Published on #Life

Rain water is pure. When you place a vessel while it is raining, you can collect pure water. It is like distilled water. By drinking that water, you will not be troubled by any ailment. When the same water is mixed up with other substances, it gets polluted. In the same manner, the mind is always pure. It gets polluted by desires. Hence, do not pollute your mind by cultivating desires. When a desire arises in your mind, brush it aside to keep your mind free from pollution. You read your text books and acquire knowledge, similarly, it is your duty to keep your mind always pure and free from pollution. This is most important learning you must acquire today.
Read more

Should we make SQL queries case sensitive?

December 8 2009 , Written by Balavardhan Reddy Published on #SQL Server2005

Should we make SQL queries case sensitive? Yes, we should.

We have so many ways to get the data from the SqlServer with Case Sensitive.

Ex :
Create table mytab
(id int,
 Name varchar(50))


Insert into mytab (1,'aaaa')
Insert into mytab (1,'AAaa')
Insert into mytab (1,'aAaa')
Insert into mytab (1,'aaAA')
Insert into mytab (1,'aaaA')


If you installed SQL Server with the default collation options you will get the same result for the below queries


Select * from mytab where Name = 'aaaa'    Output : 5 Rows
Select * from mytab where Name = 'AAaa'    Output : 5 Rows
Select * from mytab where Name = 'aAaa'    Output : 5 Rows


Alter above queries by forcing collation at the column level to get the Case sensitive results

Select * from myTab where Name COLLATE Latin1_General_CS_AS = 'aaaa'

Return only one row by Case Sensitive


If you want set the collation to entire Table you need to alter the above table like.


i) Need to find the Collate Identifier for that column
    Ex : Exec sp_help 'myTab'
   
The Output will be

    Column Name   Type           Collation
    Id            Int               NULL
    Name         Varchar    SQL_Latin1_General_CP1_CI_AS


Alter your table with Collate identifier

ALTER TABLE myTab
    ALTER COLUMN Name VARCHAR(50)
    COLLATE SQL_Latin1_General_CP1_CI_AS   

After Alter you table, you will get the Case sensitive result for the below queries also
   

Select * from mytab where Name = 'aaaa'    Output : 1 Row
Select * from mytab where Name = 'AAaa'    Output : 1 Row
Select * from mytab where Name = 'aAaa'    Output : 1 Row
   







Read more