Tutorials Hut

  • SQL Testing




  • SQL Insert Statement with Example

    SQL INSERT statement is used to insert new records in a table.

      • We can insert a new record for all columns or can insert values only for particular columns .

    Syntax:

    INSERT INTO tableName (Columns) VALUES (Values)

    Inserting a single record in a table

    INSERT INTO table
    (column1, column2, ... )
    VALUES
    (expression1, expression2, ... );

    Inserting one row, few columns at a time

    INSERT INTO Customer_Details

    (Cust_ID, Cust_Last_Name, Cust_Mid_Name,

    Cust_First_Name, Account_No, Account_Type, Bank_Branch)

    VALUES (107, ‘Robert’, ‘B.’, ‘Dan’, 3351,

    ‘Savings’, ‘Indus Bank’);

    Inserting Many rows from a Different Table

    INSERT INTO table
    (column1, column2, ... )
    SELECT expression1, expression2, ...
    FROM source_tables
    [WHERE conditions];

    Inserting NULL Value into a Column

    INSERT INTO table
    (column1, column2,Column3 ... )
    VALUES (expression1 , NULL , expression3);
    Example:

    EMPLOYEE table having below records:

    SQL Insert Statement 1

    Inserting a Record in Employee Table

    mysql> Insert into Employee (EmployeeID,Employee_FirstName,Employee_LastName,DepartmentID,EmployeeEmail,CITY,Salary) 
    Values (11,'Avadhut' , 'Patil' ,14, 'z@mail.com' , 'Kolkata' ,11000);
    Query OK, 1 row affected (0.23 sec)

    Above Record will be added in Employee Table 

    SQL Insert Statement 2 _AfterInsertingRecord



  • SQL Testing


















  • Leave a Reply

    Your email address will not be published. Required fields are marked *