SQL Insert Command

The SQL insert command is used to add or insert a single tuple or record into the table

There are 2 forms of insert command :-

  •   Insert values into all columns .
  •   Insert values into specific columns  .

Insert values into all columns

                                        The first form of insert statement allows to insert values into all columns of the table ,The values should be listed in the same order in which the corresponding columns were specifed in the create table command .



         Insert into <table-name> values(val_1,  val_2, val_3 , ................, val_n );



                            Create table Person(

                               Pid           int primary key ,

                               Name      varchar(30),

                               country    varchar(30) 



                          Insert into Person values( 1, "Pavan", "India" );


Insert values into specific columns

                                      The second form of insert command allows to specify column names that corresponding to the values  provided insert command .

      Syntax :-


    Insert into <table-name> (col_1,col_2,col_3,..........,col_n)

                                      values(val_1,val_2,val_3..........,val_n) ;


Example :-

                Consider a table which is defined in above example

                 lets insert values in specific columns.

                                           Insert into Person ( Pid , Name)

                                                               values ( 1, "Pavan" );

No comments:

Post a Comment