Pages

Social Icons

Monday, 27 February 2012

Reset Identity Column

If we want to check current identify value is. We can use this command to do so:


DBCC CHECKIDENT (‘tablename’, NORESEED)


If we wanted to check the next ID value of my orders table, I could use this command:


DBCC CHECKIDENT (orders, NORESEED)


To set the value of the next ID to be 100, I can use this command:


DBCC CHECKIDENT('Customer', RESEED, 99)


If we want to reset the identity column so we can use the previous command as follows:

DBCC CHECKIDENT('Customer', RESEED, 99)

Thursday, 23 February 2012

SQL-Server Performance Tips

Hi,


Query optimization is the required thing in SQL-Server. If we use the following steps in our query then we can get the better performance in SQL-Server.


  • Provide the primary key in all the tables
  • Avoid using the Boolean operators >, <, >=, <=, is null, is not null
  • Avoid using the Not in, !=, Like '%pattern', not exists
  • Avoid using the Calculations on unindexed columns or (use union instead), Having (use a WHERE clause instead)
  • Don't use function in where clause, instead of use that funtion in where clause.
  • Enable aliases to prefix all columns
  • use with no lock after the table name
  • Return only that column which are required
  • Those table which have less number of record use that table first in inner join
  • Try to avoid sorting in the select Statement. If possible then do the sorting at the client level.

Wednesday, 15 February 2012

Find the dependency on an object

In SQL we can find the dependency of an object with the help of TSQL. I am writing the query below which returns the all the function, stored procedure and tables which are used in that object.



SELECT DISTINCT OBJECT_NAME(d.DEPID) DEPENDENT_ON_OBJECT, OBJECT_NAME (d.ID) OBJECTNAME,o.type_desc
FROM SYS.SYSDEPENDS D inner join sys.objects o on d.depid = o.OBJECT_ID
WHERE d.ID =  OBJECT_ID('<OBJECT NAME>')

Sunday, 8 January 2012

Add a Hyperlink to a URL in SSRS


There is no direct option to create a hyperlink in SSRS, however you still can create links. This is how. To add a hyperlink




  • In report design view, right-click the text box, image, or chart to which you want to add a link and then click Properties.
  • In the Properties dialog box, click Action.
  • Select Go to URL. An additional section appears in the dialog box for this option.
  • In Select URL, type or select a URL or an expression that evaluates to a URL, or click the drop-down arrow and click the name of a field that contains a URL.
  • Click OK.
  • (Optional) The text is not automatically formatted as a link. For text, it is helpful to change the color and effect of the text to indicate that the text is a link. For example, change the color to blue and the effect to underline in the Font section in the Home tab of the Ribbon.
  • To test the link, click Run to preview the report, and then click the report item that you set this link on.


Thursday, 22 December 2011

Difference between != NULL and IS NOT NULL


When you deal with NULL in SQL Server you basically work with 3-value logic with all the implications.

IF(@myVar != null)  vs  IF(@myVar is not null)

It basically boils down to the question

what is the difference between: @myVar = null vs @myVar is null

@myVar = null will always evaluate to null as what you are asking is: is the value in @myVar equal to UNKNOWN

As you do not know what the UNKNOWN is this question cannot by answered yes, or no so it evaluates to UNKNOWN

e.g.
    "is 1 = UNKNOWN" - I do not know
    "is 'a' = UNKNOWN" - I do not know
    "is UNKNOWN = UNKNOWN" - I do not know

The last one may be a bit tricky but just imagine that you have 2 boxes with candy and you do not know neither how many candy are in box1 one nor in box2 so asking.
so the answer is I do not know

the second one @myVar is null is different as it is like asking is the value in @myVar UNKNOWN

so the difference is that you specifically ask "is it true that the value stored in the variable is UNKNOWN?", so
    "is 1 UNKNOWN" - NO
    "is 'a' UNKNOWN" - NO
    "is UNKNOWN UNKNOWN" - YES

THX,
RS

Tuesday, 13 December 2011

Notepad in C#


Hi,
I have developed a small notepad in C# windows application. In this sample notepad i have given New, Open, Save, Save As, Cut, Copy, Paste, Undo,  Select All, Find, Word-wrap, Font and Color functionality.


Here I am attaching a zip file of the source code. Download Here


Thx,
RS

Thursday, 1 December 2011

Call jquery funtion when it is exist.


Some times we need to call a function after chceking that it is exist there or not. This is very simple in jquery. Use that function name in if and if is exist then it will go in if block.


Example : 
function temp(){
  // Sample Code
}

if(temp){
  temp();
}


Like this temp function execute only when it is awailable.