Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • SQL Insert Statement

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 225
    Comment on it

    SQL insert statement is used to insert the data in a table in database . Using this statement we can insert single or multiple data in a table .
    We can insert the data by two ways :
    1) By SQL insert into statement : we can insert data either by column name or without column name .
    2) By SQL select statement

    1) By SQL insert into statement : If you don't want to use select statement to insert the data then you can insert directly , example given below .
    Syntax :

    insert into table_name ( col_name1 ,  col_name2 ,  col_name3 , ............... col_nameN) values ( value1 , value2 , value3 , ..................valueN) ;
    

    Example :

    insert into Employee_Info ( Employee_name , Employee_Age , Employee _Salary )  values ( Mukesh , 23 , 100000 );
    insert into Employee_Info ( Employee_name , Employee_Age , Employee _Salary )  values ( Ayush , 24 , 200000 );
    insert into Employee_Info ( Employee_name , Employee_Age , Employee _Salary )  values ( Ishan , 20 , 400000 );
    insert into Employee_Info ( Employee_name , Employee_Age , Employee _Salary )  values ( Pranav , 35 , 700000 );
    insert into Employee_Info ( Employee_name , Employee_Age , Employee _Salary )  values ( Abhishek , 26 , 800000 );
    insert into Employee_Info ( Employee_name , Employee_Age , Employee _Salary )  values ( Ravi , 25 , 300000 );
    insert into Employee_Info ( Employee_name , Employee_Age , Employee _Salary )  values ( David , 40 , 800000 );
    

    Table name : Employee_Info

     Employee_name            Employee_Age          Employee _Salary
          Mukesh                  23                           100000
          Ayush                   24                           200000
          Ishan                   20                           400000
          Pranav                  35                           700000
          Abhishek                26                           800000
          Ravi                    25                           300000
          David                   40                           800000
    

    If you ignore the column name , then It will also work like :
    Syntax :

    insert into table_name values ( value1 , value2 , value3 , ..................valueN ) ;
    

    Example :

    It will also generate same result ;

     insert into Employee_Info  values ( Mukesh , 23 , 100000 );
        insert into Employee_Info  values ( Ayush , 24 , 200000 );
        insert into Employee_Info   values ( Ishan , 20 , 400000 );
        insert into Employee_Info  values ( Pranav , 35 , 700000 );
        insert into Employee_Info  values ( Abhishek , 26 , 800000 );
        insert into Employee_Info  values ( Ravi , 25 , 300000 );
        insert into Employee_Info values ( David , 40 , 800000 );
    

    2) By SQL select statement

      insert into table_name ( col_name1 ,  col_name2 ,  col_name3 , ............... col_nameN) values select  col_name1 ,  col_name2 ,  col_name3 , ............... col_nameN from table_name where clause ;
    

    If you want to add a new row then you can also add , but remember , that column name should be matched with that data type .

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: