The MySQL INSERT statement is used to insert data into a table. The syntax for the INSERT statement is as follows:

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

Here, 'table_name' is the name of the table where data needs to be inserted, and 'column1', 'column2', 'column3', etc. are the names of the columns in the table. The 'VALUES' keyword is used to specify the values that need to be inserted into each column.

For example, let's say we have a table named 'employees' with the following columns: 'id', 'name', 'age', and 'salary'. To insert a new employee into the table, we can use the following INSERT statement:

INSERT INTO employees (id, name, age, salary)
VALUES (1, 'John Doe', 25, 50000);

This will insert a new row into the 'employees' table with the values '1' for the 'id' column, 'John Doe' for the 'name' column, '25' for the 'age' column, and '50000' for the 'salary' column.

We can also insert multiple rows into a table using a single INSERT statement. For example:

INSERT INTO employees (id, name, age, salary)
VALUES (2, 'Jane Smith', 30, 60000),
       (3, 'Bob Johnson', 35, 70000),
       (4, 'Sarah Lee', 28, 55000);

This will insert three new rows into the 'employees' table with the specified values for each column.

MySQL INSERT Statement: A Comprehensive Guide with Examples

原文地址: https://www.cveoy.top/t/topic/nYYb 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录