MySQL Insert Statement [ 2024 ]
MySQL Insert Statement
In this tutorial, we will learn about the MySQL INSERT statement. There are multiple methods to get data into MySQL tables, the INSERT statement is the most common.
Syntax
INSERT statement uses the following syntax:
mysql> INSERT INTO table_name (column_list)
VALUES (comma_separated_value_list);
The number of columns and values must be the same. String and temporal data types column values must be enclosed in single quotes in the INSERT statement.
Multiple Inserts
The Syntax for multiple inserts into the table is as follows:
For example, the statement to insert three rows into the table:
mysql> INSERT INTO table_name (column_list)
VALUES (values_list), (values_list), (values_list)
We can also omit some column names in the INSERT statement. In general, if a column has no default value, the effect of omitting it from the INSERT statement depends on whether it accepts NULL and other conditions:
- If the column can accept NULL, it is set to NULL.
- If the column has default constraint, it is set to the implicit default for the column data type if strict SQL mode is not enabled. If the strict mode is enabled, an error occurs.
- To get the next available number in an AUTO_INCREMENT column, we can leave the column out of the column list in the INSERT statement.
Example
https://www.testingdocs.com/insert-data-into-a-mysql-database-table/
—
MySQL Tutorials
MySQL Tutorials on this website:
For more information on MySQL Database: