MySQL 向特定行和列插入值

mysqlmysqli database更新于 2024/8/9 13:32:17

首先我们创建一个表 −

mysql> create table DemoTable1569
   -> (
   -> StudentId varchar(10),
   -> StudentName varchar(20)
   -> );
Query OK, 0 rows affected (3.05 sec)

使用 insert 命令在表中插入一些记录 −

mysql> insert into DemoTable1569 values('John_12','John Smith');
Query OK, 1 row affected (0.38 sec)
mysql> insert into DemoTable1569 values('David_321','Carol Taylor');
Query OK, 1 row affected (0.50 sec)
mysql> insert into DemoTable1569 values('David_989','David Miller');
Query OK, 1 row affected (0.24 sec)

使用 select 语句显示表中的所有记录 −

mysql> select * from DemoTable1569;

这将产生以下输出 −

+-----------+--------------+
| StudentId | StudentName  |
+-----------+--------------+
| John_12   | John Smith   |
| David_321 | Carol Taylor |
| David_989 | David Miller |
+-----------+--------------+
3 rows in set (0.00 sec)

这是向特定行和列插入值的查询。

mysql> update DemoTable1569 set StudentId='Carol_321' where StudentName='Carol Taylor';
Query OK, 1 row affected (0.26 sec)
Rows matched: 1  Changed: 1 Warnings: 0

让我们再次检查表记录。

mysql> select * from DemoTable1569;

这将产生以下输出 −

+-----------+--------------+
| StudentId | StudentName  |
+-----------+--------------+
| John_12   | John Smith   |
| Carol_321 | Carol Taylor |
| David_989 | David Miller |
+-----------+--------------+
3 rows in set (0.00 sec)

相关文章


有用资源