Home > Database > Mysql Tutorial > body text

How to insert data command line statement in mysql

下次还敢
Release: 2024-04-05 17:45:14
Original
1049 people have browsed it

How to use the MySQL command line to insert data

In MySQL, you can use the following INSERT statement to insert data into the database:

<code>INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);</code>
Copy after login

Where:

  • table_name is the name of the table into which data is to be inserted.
  • column1, column2, ... are the column names into which values ​​are to be inserted.
  • value1, value2, ... are the values ​​to be inserted.

Example

Suppose there is a table named "customers" with the following columns:

  • id(integer, Primary key)
  • name (string)
  • age (integer)

To insert a child named "John Doe" with an age of 30 into this table For customers, you can use the following command:

<code>INSERT INTO customers (name, age) VALUES ('John Doe', 30);</code>
Copy after login

Other considerations

  • Make sure that the inserted value matches the data type of the column.
  • For string values, use single or double quotes to surround the value.
  • For date and time values, use the appropriate format (for example, for dates, use the 'YYYY-MM-DD' format).
  • You can use the VALUES clause to insert multiple rows at once.
  • You can use the ON DUPLICATE KEY UPDATE clause to update an existing row when the insert fails.

The above is the detailed content of How to insert data command line statement in mysql. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!