【Mysql basic commands/query: how to update the message/record data of each row】

发布时间:2023年12月21日

mysql common commands

I) desc, insert and update

desc = describe,
insert into subject values(null,“Geometry Politics”, 99);

mysql> select * from subject;
+------------+----------------------+---------------+
| subject_id | subject_name         | subject_hours |
+------------+----------------------+---------------+
|          1 | Communication skills |           100 |
+------------+----------------------+---------------+
1 row in set (0.00 sec)

mysql> desc subject;
+---------------+-------------+------+-----+---------+-------+
| Field         | Type        | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| subject_id    | int(11)     | YES  |     | NULL    |       |
| subject_name  | varchar(20) | YES  |     | NULL    |       |
| subject_hours | int(11)     | YES  |     | NULL    |       |
+---------------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql> insert into subject values(null,"Geometry Politics", 99);
Query OK, 1 row affected (0.00 sec)

mysql> select * from subject;
+------------+----------------------+---------------+
| subject_id | subject_name         | subject_hours |
+------------+----------------------+---------------+
|          1 | Communication skills |           100 |
|       NULL | Geometry Politics    |            99 |
+------------+----------------------+---------------+
2 rows in set (0.00 sec)

mysql> update subject set subject_id = 3 where subject_hours = 99
    -> ;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from subject;
+------------+----------------------+---------------+
| subject_id | subject_name         | subject_hours |
+------------+----------------------+---------------+
|          1 | Communication skills |           100 |
|          3 | Geometry Politics    |            99 |
+------------+----------------------+---------------+
2 rows in set (0.00 sec)

mysql> describ subject;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'describ subject' at line 1
mysql> describe subject;
+---------------+-------------+------+-----+---------+-------+
| Field         | Type        | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| subject_id    | int(11)     | YES  |     | NULL    |       |
| subject_name  | varchar(20) | YES  |     | NULL    |       |
| subject_hours | int(11)     | YES  |     | NULL    |       |
+---------------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
文章来源:https://blog.csdn.net/DavidsonGong/article/details/135120437
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。