MySQL 在特定行和列中插入一个值
我们首先创建一个表-
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)
广告