Home > Database > Mysql Tutorial > How to enter data after creating a table in mysql

How to enter data after creating a table in mysql

下次还敢
Release: 2024-04-22 19:48:33
Original
391 people have browsed it

The methods for inserting data into a MySQL table include: 1. INSERT statement; 2. LOAD DATA INFILE statement to load CSV files in batches; 3. Direct insertion using client tools.

How to enter data after creating a table in mysql

MySQL How to input data after creating the table

After creating the table, you can insert into the MySQL table through the following methods Data:

1. INSERT statement

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

For example:

<code class="sql">INSERT INTO customers (name, email, phone) 
VALUES ('John Doe', 'john.doe@example.com', '123-456-7890');</code>
Copy after login

2. LOAD DATA INFILE statement

This method can be used to batch load data using CSV or other delimited files.

<code class="sql">LOAD DATA INFILE 'file_path.csv' INTO TABLE table_name
FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'
(column1, column2, ...);</code>
Copy after login

For example:

<code class="sql">LOAD DATA INFILE 'customers.csv' INTO TABLE customers
FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'
(name, email, phone);</code>
Copy after login

3. Use client tools

You can directly insert data into the table through MySQL Workbench or other client tools.

Note:

  • Make sure the column names match the inserted data values.
  • Provide values ​​for all non-null columns.
  • For date and time types, please use the corresponding format.
  • Use transactions to ensure data integrity.

The above is the detailed content of How to enter data after creating a table 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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template