Home > Database > Mysql Tutorial > How to write mysql add data statement

How to write mysql add data statement

下次还敢
Release: 2024-04-05 18:00:23
Original
1197 people have browsed it

MySQL uses the INSERT statement to insert data into the table. The syntax is: INSERT INTO

( <column name>, ... ) VALUES ( , ... ). Parameters include:
: the name of the table into which data is to be inserted; <column name>: the name of the column into which data is to be inserted; : the value in the column to be inserted. For example, to insert a row of data into a table named employees: INSERT INTO employees (id, name, email) VALUES (1, 'John Doe

How to write mysql add data statement

MySQL Add Data Statement

The statement used to insert data into the table in MySQL is the INSERT statement.

Syntax:

<code class="sql">INSERT INTO <表名> ( <列名>, ... ) VALUES ( <值>, ... );</code>
Copy after login

Parameters:

  • <Table Name>: The name of the table into which data is to be inserted.
  • <Column name>: The name of the column to be inserted into, which can be a single column or multiple columns.
  • <Value>: To insert the value in the column, it can be a single value or multiple values.

Usage example:

Suppose we have a class named employees table, which contains three columns: id, name and email. The following statement will insert a row of data into the table:

<code class="sql">INSERT INTO employees (id, name, email) VALUES (1, 'John Doe', 'john.doe@company.com');</code>
Copy after login

Note:

  • The order of the inserted values ​​must be consistent with the order of the columns in <Column Name>.
  • If <column name> is not specified, the value will be inserted into all columns in the table.
  • If you want to insert a NULL value, you need to specify # in the value ##NULL.
  • Rows can be inserted multiple times using the
  • VALUES() clause, as shown below:
<code class="sql">INSERT INTO employees (id, name, email) VALUES
(2, 'Jane Doe', 'jane.doe@company.com'),
(3, 'John Smith', 'john.smith@company.com');</code>
Copy after login

The above is the detailed content of How to write mysql add data statement. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template