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«

No comments:

Post a Comment