Monday, December 15, 2008

Small trick to speed up your select query

If you want to select data from a database table, but somebody else is inserting data in same table, then in general case, you will have to wait till the insert completes. Your query is deadlocked.

 

In many cases, the dead lock is justified. It is because, the select data will be more correct after the insertion completes. But it may not be the case always. If you want to select sales data from 2005 to 2007, but someone is inserting data of date 2008, then you will have nothing to do with what other is inserting. In such case, you can use nolock keyword of SQL Server, to perform select operation. It simply allows performing raw read in the table. It ignores locks and also does not lock the table. So, the select operation becomes faster.

 

It is used like this.

 

Select *

From    CSAVatInvoiceHdr a (nolock)

Where  csavatinvoicedt >= '2005-01-01'

And      csavatinvoicedt <= '2007-01-01'

Read more...

Friday, December 5, 2008

User Name does not show up in Task Manager

Through Task Manager, one can find out the services running on a windows machine. I usually use it to find out unnecessary processes and stop them or to find out the memory usage of a process.

 

Sometimes, may be due to some virus, username in Processes tab of Task Manager may not show up.

 

If so, then Go to Run -> Type Services.msc and press Enter -> Search for Terminal Process in right tab -> Right Click it and select Properties -> in Properties Tab set its start up type to Automatic and click Apply -> Click Start to start the process. This will show up the User Name in Task Manager.

 

Usually harmful processes run with username as that of windows user not as System or others. So, it is helpful to find out suspicious processes.

 

 

Read more...

Wednesday, December 3, 2008

Faster way to get rowcount on sql table

 

If you want to get the number of rows of a sql table, you would probably think of using count keyword of sql server. If "retailer" is a sql table, then it would look like this.

 

select            count(*)

from     retailer

 

It gives the result, but it would be costlier in case of CPU usage and time as it uses an aggregate function count.

The query can be optimized as follows.

 

select rowcnt

from sysindexes

where id = object_id('retailer')

and indid = 1

 

sysindexes is a system table that contains details of indexes and tabular objects (table, views). This query will have lesser cost compared to previous one so, results faster. It may be beneficial when there are millions of data in the table or when row count is to be obtained repeatedly.

 

 

Read more...

Monday, December 1, 2008

Comments in different Programming Languages

Comments are helpful medium for storing useful information in application codes while developing it. A successful software is not only represented by how well it does it task but also by how well it is documented and how well it's programming logic can be understood by a new comer. So, the software enhancements can be supported by new comer, which helps in long run of the software.

 

Without writing any further on its usefulness, I will directly move to the topic. There are two types of comments in programming languages. One is single line comment, which works for the line where it is given. It usually has starting mark but no ending mark. Other is multi-line comment, which works for until the closing mark is found.

 

Comment in C, C++, C#, PHP

A single line comment is preceded by double slash (//).  An example is shown below.

 

//function to reverse an array

Int reverse(int a[])

{

            //code goes her

}

No doubt, you can use double slash to comment multiple consecutive lines provided that each line is preceded by double slash (//).

Multi-line comment starts with single slash and an asterisk sign (/*) and ends with (*/).

 

Int reverse(int a[])

/*function to

            reverse an array */

 

This commenting style is applicable for many programming languages.

 

Comment in VB, ASP, VBScript

Single line comment is preceded by single apostrophe (').

 

Comment in SQL Server

Single line comment is preceded by double dash (--) while multi-line comment is represented by text between (/*) and (*/) marks.

If you give comment inside comment, then also whole thing is represented as comment.

 

Comment in HTML

Multi-line comment begins with (<!--) and ends with (--!>). An example is shown below.

<!--<div id="footer">                   

                    ©2008 Aptech Suraj Lubhu

                </div>-->

 

Comment in JavaScript

Comment in JavaScript is similar as in C and C++. Single line comment is preceded by double slash (//) while multi-line comment begins with (/*) and ends with (*/) marks.

 

Comment in CSS Style Sheets

Multi-line comments in CSS are preceded by (/*) and followed by (*/).

 

Read more...