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

mysql common commands

I) desc, insert and update

desc = describe,

insert into subject values(null,"Geometry Politics", 99);

sql 复制代码
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)
相关推荐
2501_9159214315 分钟前
uni-app一键生成iOS安装包并上传TestFlight全流程
android·ios·小程序·https·uni-app·iphone·webview
studyForMokey25 分钟前
【Android面试】四大组件专题 todo
android·面试·职场和发展
柒.梧.28 分钟前
MySQL索引优化+慢查询全解析
数据库·mysql
captain37629 分钟前
数据库约束
mysql
qq_3537375436 分钟前
网站 Favicon 获取 API 技术实现指南
android
呆瑜nuage41 分钟前
MySQL数据类型全解析
数据库·mysql
Harvy_没救了42 分钟前
MySQL主从架构深度解析:原理、优化与实践指南
运维·mysql·架构
stevenzqzq43 分钟前
Android Navigation 组件页面跳转方法说明
android·compose
黑牛儿1 小时前
MySQL 实战进阶:从单表优化到分布式数据库适配
数据库·分布式·mysql
momin~1 小时前
MySQL-part3【数据库约束、表设计】
数据库·mysql