mysql第五课
程序员文章站
2022-04-14 16:44:28
修改表中一行或多行数据: SELECT*FROM student;+ + + +| id | name | ban |+ + + +| 1 | yy | 1913 || 7 | ss | 1923 || 8 | 许 | 1913 || 9 | 应 | 1913 || 10 | Aron | 1913 ......
修改表中一行或多行数据:
select*from student;
+----+------+------+
| id | name | ban |
+----+------+------+
| 1 | yy | 1913 |
| 7 | ss | 1923 |
| 8 | 许 | 1913 |
| 9 | 应 | 1913 |
| 10 | aron | 1913 |
+----+------+------+
5 rows in set
+----+------+------+
| id | name | ban |
+----+------+------+
| 1 | yy | 1913 |
| 7 | ss | 1923 |
| 8 | 许 | 1913 |
| 9 | 应 | 1913 |
| 10 | aron | 1913 |
+----+------+------+
5 rows in set
update student set name="yiyq"where ban=1913;
query ok, 4 rows affected
rows matched: 4 changed: 4 warnings: 0
query ok, 4 rows affected
rows matched: 4 changed: 4 warnings: 0
检查:select*from student;
+----+------+------+
| id | name | ban |
+----+------+------+
| 1 | yiyq | 1913 |
| 7 | ss | 1923 |
| 8 | yiyq | 1913 |
| 9 | yiyq | 1913 |
| 10 | yiyq | 1913 |
+----+------+------+
5 rows in set
+----+------+------+
| id | name | ban |
+----+------+------+
| 1 | yiyq | 1913 |
| 7 | ss | 1923 |
| 8 | yiyq | 1913 |
| 9 | yiyq | 1913 |
| 10 | yiyq | 1913 |
+----+------+------+
5 rows in set
删除数据:select*from accout;
+----+------+-------+
| id | name | money |
+----+------+-------+
| 1 | a | 800 |
| 2 | b | 1200 |
+----+------+-------+
2 rows in set
+----+------+-------+
| id | name | money |
+----+------+-------+
| 1 | a | 800 |
| 2 | b | 1200 |
+----+------+-------+
2 rows in set
delete from accout where name="a";
query ok, 1 row affected
query ok, 1 row affected
select*from accout;
+----+------+-------+
| id | name | money |
+----+------+-------+
| 2 | b | 1200 |
+----+------+-------+
1 row in set
+----+------+-------+
| id | name | money |
+----+------+-------+
| 2 | b | 1200 |
+----+------+-------+
1 row in set
创建表时创建索引:
index id;
truncate也是删除数据,但它是删除一个表在重建一个相同的表。
创建索引:
create [unique/fulltext/spatial] index 索引名 on 表名 (字段名 [(长度)] [asc/desc]);
普通索引什么都不加,
unique:可选参数,表示唯一约束,
fulltext:可选参数,表示全文约束
spatial:可选参数,表示空间约束
用alter创建:
alter table 表名 add [unique/fulltext/spatial] index 索引名(字段名[(长度)] [asc/desc]);
普通索引:alter table book add index inter_id(bookid);
删除索引:
1.alter table 表名 drop index 字段名;
2.drop index 索引名 on 表名;
上一篇: Python:GUI
下一篇: 基本流程图的制作-通过在线制图工具绘制