Thursday, May 20, 2010

Difference Between function and Procedure

1. Function is mainly used in the case where it must return a value. Where as a procedure may or may not return a value or may return more than one value using the OUT or INOUT parameter.

2. Function can be called from SQL statements where as procedure can not be called from the sql statements 

3.Stored Procedure: supports deferred name resolution. Example while writing a stored procedure that uses table named tabl1 and tabl2 etc..but actually not exists in database is allowed only in during creation but runtime throws error Function wont support deferred name resolution. 

4.Stored procedure returns always integer value by default zero. where as function return type could be scalar or table or table values

5. Stored procedure is precompiled execution plan where as functions are not.

6.A procedure may modify an object where a function can only return a value The RETURN statement immediately completes the execution of a subprogram and returns control to the caller. 

7.Function can take only input aurguments, but procedure may take both input and out put parameters.
8) You can have DML(insert,update, delete) statements in a function. But, you cannot call such a function in a SQL query.
eg: suppose, if u have a function that is updating a table.You can't call that function in any sql query.
- select myFunction(field) from sometable; will throw error.
9.There is possible of recurssive functionlike max(min(something)),but there is nothing like in procedure.

10.We can call a function from a procedure, but it is not possible to call a procedure from a function
11.Functions cannot affect the state of the database which means we cannot perform insert,delete,update and create operations 
operations on the database.Stored Procedures  can affect the state of the database by using insert,delete,update and create  operations. 
12.Functions are basically used to compute values. We passes some parameters to functions as input and then it performs some operations on the parameter and return output.
Stored procedures are basically used to process the task.
13.Function can not change server environment and our operating system environment.
Stored procedures can change server environment and our operating system environment. 

Tuesday, May 18, 2010

How to Insert Multiple Rows in SQL Server

To insert multiple rows with the help of single query you can use following syntax. Regarding performance there is not much difference. If there is performance difference it does not matter as we can use this for one time insert script.

INSERT INTO Table1 (FirstColumn, SecondColumn)
SELECT 'First' ,1
SELECT 'Second' ,2
SELECT 'Third' ,3
SELECT 'Fourth' ,4
SELECT 'Fifth' ,5

  Into daTable
     ( col1, col2, ... coln )
     ( '21',   9,  ... 'oh' )
    ,( '22',  37,  ... 'my' )
    ,( '23',  42,  ... 'we' )
    ,( '24',  11,  ... 'be' )
    ,( '25',  77,  ... 'at' );

Sunday, May 16, 2010



Meri Har Ek Ada Mein Chhupi Thi Meri Tamanna
Tum ne Mehsoos Na Ki Ye Aur Baat Hai

Maine Har Dam Tere Hi Khwab Dekhe
Mujhe Tabeer Na Mili Ye Aur Baat Hai

Maine Jab Bhi Tujh se Baat Karna Chaha
Mujhe Alfaz Na Mile Ye Aur Baat Hai

Main Meri Tamanna Ke Samundar Mein Door Tak Nikla
Mujhe Saahil Na Mila Ye Aur Baat Hai

Qudrat Ne Likha Tha Tujhko Meri Tamanna Mein,
Teri Qismat Mein Main Na Tha Ye Aur Baat Hai…

Aankho Main Meri bhi Chahat thi Teri
Tune Meri Aankhe na Padhi ye Aur Baat Hai

Dunya ke Liye Maine Deen ko Bhula Diya Apne
Phir bhi Mujhe Dunya na Mili ye Aur Baat Hai

Tabeer- Meaning of Dream
Sahil - Bank of River


Kaun aayega yahan?
Na koi aaya hoga..
Mera darwaja hawaon ne hilaya hoga

Dil-e-nadan na dhadak
Koi khat leke padosi ke ghar aaya hoga

Gul se lipti hui titali ko gira kar dekho
Aandhiyon tumne darakhto ko to giraya hoga

Aye sanam,pardes mei mat yaad karo apna makan
Abke barisho ne use tod giraya hoga…………..

Mujhe barbad kerne me 
Dushmano ka hi nahi sara kasoor
Mere dosto ne bhi isme jor lagaya hoga.