Home > Database > Mysql Tutorial > body text

How do we insert data into a MySQL table?

王林
Release: 2023-09-07 18:41:02
forward
1592 people have browsed it

我们如何向 MySQL 表中插入数据?

To insert data into a MySQL table, we need to use the INSERT INTO command. We have to specify the values ​​of all the columns in the table in the INSERT INTO command.

Syntax

INSERT INTO table_name values(value1,value2,…)
Copy after login

Example

Suppose we have a table named "Student" which contains three columns "RollNo", "Name" and "Class", then With the help of the following query we can add new rows to the table -

mysql> INSERT INTO Student values(50,'Harshit',’B.tech’);
Query OK, 1 row affected (0.07 sec)

mysql> INSERT INTO Student values(56,'Amit',’M.tech’);
Query OK, 1 row affected (0.05 sec)

mysql> Select * from Student;
+---------+-------------+-----------+
| RollNo  | Name        | Class     |
+---------+-------------+-----------+
|  50     | Harshit     | B.tech    |  
|  56     |  Amit       | M.tech    |
+---------+-------------+-----------+
2 rows in set (0.00 sec)
Copy after login

The above is the detailed content of How do we insert data into a MySQL table?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
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