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

How to enter data after creating a table in mysql

下次还敢
下次还敢Original
2024-04-22 19:48:33460browse

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>

For example:

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

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>

For example:

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

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!

Statement:
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