Geek Slack

My SQL Tutorial
    About Lesson



    MySQL INSERT INTO Statement


    MySQL INSERT INTO Statement

    The INSERT INTO statement in MySQL is used to add new records into a table.

    Basic Syntax:

    Example: Basic INSERT INTO

    INSERT INTO table_name (column1, column2, ...)
    VALUES (value1, value2, ...);

    This SQL command inserts a new row into the table_name table with specified values for columns column1, column2, etc.

    Example Using INSERT INTO:

    Example: Inserting Data

    INSERT INTO users (first_name, last_name, email)
    VALUES ('John', 'Doe', 'john.doe@example.com');

    This SQL command inserts a new user into the users table with first name John, last name Doe, and email john.doe@example.com.

    Inserting Multiple Rows:

    Example: Inserting Multiple Rows

    INSERT INTO users (first_name, last_name, email)
    VALUES ('Jane', 'Smith', 'jane.smith@example.com'),
           ('Michael', 'Brown', 'michael.brown@example.com');

    This SQL command inserts two new users into the users table, one with first name Jane, last name Smith, and email jane.smith@example.com, and the other with first name Michael, last name Brown, and email michael.brown@example.com.

    Conclusion

    The INSERT INTO statement is fundamental in MySQL for adding new records into database tables, allowing for the insertion of single or multiple rows with specified values for each column.