msql 表insert select update delete (三)

1.插入数据 insert into 表名 values("字段1“,字段2.)
mysql> insert into classes values(null,"WuLiu",98);
Query OK, 1 row affected (0.01 sec)

多行插入

mysql> insert into classes values(3,"GuanLi",22),(4,"KuaiJi",55);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> desc classes;
+-------+------------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+------------------+------+-----+---------+----------------+
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| name  | varchar(10)      | YES  |     | NULL    |                |
| num   | int(11)          | YES  |     | NULL    |                |
+-------+------------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

mysql> select * from classes;
+----+-----------+------+
| id | name      | num  |
+----+-----------+------+
|  1 | DianShang |   48 |
|  2 | WuLiu     |   98 |
|  3 | GuanLi    |   22 |
|  4 | KuaiJi    |   55 |
+----+-----------+------+
4 rows in set (0.00 sec)
2.查询数据
mysql> select * from classes;
+----+-----------+------+
| id | name      | num  |
+----+-----------+------+
|  1 | DianShang |   48 |
|  2 | WuLiu     |   98 |
+----+-----------+------+
2 rows in set (0.00 sec)

mysql> insert into students(id,name,age,gender) values(null,'xiaobao',25,'man');
Query OK, 1 row affected (0.00 sec)

mysql> select * from students;
+----+---------+------+------+--------+--------+
| id | name    | age  | high | gender | cls_id |
+----+---------+------+------+--------+--------+
|  1 | dabao   | NULL | NULL | NULL   |   NULL |
|  2 | xiaobao |   25 | NULL | man    |   NULL |
+----+---------+------+------+--------+--------+
2 rows in set (0.00 sec)

3.update 表 set 字段名=值”where 条件;

mysql> update students set age=56 where name='dabao';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from students;
+----+---------+------+------+--------+--------+
| id | name    | age  | high | gender | cls_id |
+----+---------+------+------+--------+--------+
|  1 | dabao   |   56 | NULL | NULL   |   NULL |
|  2 | xiaobao |   25 | NULL | man    |   NULL |
+----+---------+------+------+--------+--------+
2 rows in set (0.00 sec)

4.delete from 表名字 where条件;

delete from students where id=2;

mysql> delete from classes where id=2;
Query OK, 1 row affected (0.00 sec)

数据库备份:

mysqldump -uroot -p school_data > school_data1.sql
 

发布了50 篇原创文章 · 获赞 1 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/u010708028/article/details/103960754