MySQL INSERT Statement

MySQL INSERT Statement

MySQL INSERT statement is used to insert data in MySQL table within the database. We can insert single or multiple records using a single query in MySQL.

Syntax:

The SQL INSERT INTO command is used to insert data in MySQL table. Following is a generic syntax:

  1. INSERT INTO table_name ( field1, field2,…fieldN )
  2. VALUES
  3. ( value1, value2,…valueN );
  4. Syntax for all fields:
    1. INSERT INTO table_name VALUES ( value1, value2,…valueN );

    MySQL INSERT Example 1: for all fields

    If you have to store all the field values, either specify all field name or don’t specify any field.

    Example:

    1. INSERT INTO emp VALUES (7, ‘Sonoo’, 40000);

    MySQL INSERT Example 2: for partial fields

    In such case, it is mandatory to specify field names.

    1. INSERT INTO emp(id,nameVALUES (7, ‘Sonoo’);

    MySQL INSERT Example 3: inserting multiple records

    Here, we are going to insert record in the “cus_tbl” table of “customers” database.

    1.  INSERT INTO cus_tbl
    2. (cus_id, cus_firstname, cus_surname)
    3. VALUES
    4. (5, ‘Ajeet’‘Maurya’),
    5. (6, ‘Deepika’‘Chopra’),
    6. (7, ‘Vimal’‘Jaiswal’);

    Visual Representation:

    new

    See the data within the table by using the SELECT command:

    new1

One thought on “MySQL INSERT Statement

Comments are closed.