Tuesday, December 23, 2014

Different Ways To Insert Records Into A Table In Sql Server

1.Simple 

Syntax :-
       INSERT INTO table_name
       VALUES
       (value_1,value_2,....,value_n)

    * Here number of values supplied (that is n) must be equal to number of columns in the table

2.Insert into specific column

Syntax :-
       INSERT INTO table_name(column_1,column_2,....,column_m)
       VALUES
       (value_1,value_2,....,value_m)

 * Here number of values supplied (that is m) must be equal to number of specified columns in the table

Remarks:-
  • Unspecified column will be assigned with default value(if specified) or NULL .
  • Here the Specified column must include column with primary key constraint(if defined).

3.Insert Multiple Rows In Single Query

Syntax :-
       INSERT INTO table_name 
       [(column_1,column_2,....,column_m)]     --specify columns
       VALUES
       (value_1,value_2,....,value_n),  --row_1
       (value_1,value_2,....,value_n),  --row_2
       .
       .
       .
       .
       .
       (value_1,value_2,....,value_n),  --row_m

*Here m rows will be inserted into the specified table


Done
»Keep Sharing and Learning«

Thursday, December 4, 2014

An Interview Question For C# Programmers

Q: Consider following code snippet 


int i=5; 
i=i++;

Please find original post from here


after these two lines what will be the value of  i ?

 Ans: 5

illustration: -       

Please find original post from here

Most of us answer 6 but it's not the case, Value of i remains unchanged (i remains as 5). But somewhere along the execution, value of i was 6 but it is assigned with value 5 finally.

Consider the following program


class Program
{
    static int i;
    static void Main(string[] args)
    {
        i = 5;
        i = postIncrement();
    }
    static int postIncrement()
    {
        return i++;
    }
}
separate function for post Increment is written for better understanding of problem.Now While debugging the program in visual studio it will look like this
Image Showing Debugging of the problem
Debugging of the problem in VS 2012


Steps Involved:-

1. i initialised to 5.


2. i++ operator returns 5 but not assigned to i.

3. i++ operator increments value of  i  to 6.


4. i is assigned with 5 which is the value returned by i++ in step 2.


try to solve related questions like

int i=5; 
i=(i++)+i+(++i);




Please find original post from here

after thes two lines what will be the value of i? Comment you answer please.


◙ Done.Happy Coding   
»Keep Sharing and Learning«