• Home
  • SQL INSERT INTO Statement

    To insert data into a table in SQL, you can use the INSERT INTO statement. The INSERT INTO statement allows you to specify the table name and the values to be inserted into the respective columns. The basic syntax of the INSERT INTO statement is as follows:

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

    Here's an example that demonstrates how to use the INSERT INTO statement to insert a new row into a table called "employees":


    sql
    INSERT INTO employees (name, age, department, salary)
    VALUES ('John Doe', 30, 'Sales', 5000);

    In the example above, the INSERT INTO statement specifies the table name "employees" and the columns "name", "age", "department", and "salary" that the values will be inserted into. The VALUES clause provides the corresponding values for each column in the same order.


    If you're inserting values into all columns of the table and in the same order as the table's column structure, you can omit the column names from the INSERT INTO statement. Here's an example:

    sql
    INSERT INTO employees
    VALUES ('John Doe', 30, 'Sales', 5000);

    In this case, the column names are omitted, assuming that the values provided in the VALUES clause align with the table's column structure.


    You can insert multiple rows at once by specifying multiple sets of values in the VALUES clause. Each set of values is enclosed within parentheses and separated by commas. Here's an example:

    sql
    INSERT INTO employees (name, age, department, salary)
    VALUES ('John Doe', 30, 'Sales', 5000),
        ('Jane Smith', 35, 'Marketing', 6000),
        ('Mike Johnson', 28, 'Finance', 5500);

    In the example above, three rows are inserted into the "employees" table with different sets of values.


    Remember to replace "table_name" with the actual name of your table and adjust the column names and values according to your specific database structure and requirements.



    About the Author



    Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

    We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





     PreviousNext