Saturday, January 25, 2014

SQL Server Management Studio Custom Quarry Shortcuts

How to create a custom quarry short cut ?

Step 1: Go to Tools>Options>Environment >Keyboard























Step 2: Now Create your own short cut (e.g. SELECT  TOP 100 * FROM)












Step 3: Refresh SSMS intellisense by pressing Ctrl + Shift + R 

Step 4: Test the short cut, highlight the table and press Ctrl +3












Like wise you can create your own shortcuts...

Wednesday, January 15, 2014

C#.net Conditional Operator Usage Tip

The && and || operators both “short circuit” when necessary. This means that after a complex expression
has been determined to be false, the remaining subexpressions will not be checked. If you require all expressions
to be tested regardless, you can use the related & and | operators.

Don't Depend on SQL Sever Sorting

Resonantly i have found a bug in production system. Where i have to uploaded data to temporary data base and import that data to another data  structure.
Data import part will happen in pre-define time schedule but not in same time. In my case data will be imported by using order of data upload . I have read data from data base without ordering the data. It work for some time more than one year. But suddenly system has generated errors due to some reason. I have done some digging. In addition i have found out that data has imported but not in intended order.
I have put order by clause in to select statement.That has resolved the my production issue. Unfortunately this error was not able to generate in local environment.
Therefore its always good to retrieve data with order by clause

Sample Code to test this scenario

 USE tempdb;
 -- Create Table

 CREATE TABLE dbo.TempData
 (ID INT IDENTITY(1,1) PRIMARY KEY
  ,Col1 INT)
 -- Insert Random data
  DECLARE @Count INT =0

  WHILE @Count < 1000
  BEGIN
 INSERT INTO dbo.TempData(Col1) VALUES(rand()*100000)
 SET @Count= @Count+1
  END
 --Select Top 10 records

  SELECT top 10* FROM dbo.TempData

















--Create Nonclusterd index on Col1

CREATE  NONCLUSTERED INDEX [TempData_Col1] ON dbo.TempData (Col1 ASC)


 --Select Top 10 records


SELECT top 10* FROM dbo.TempData