mysql第五课
修改表中一行或多行数据:
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 表名;
相关推荐
ribavnu 2020-11-16
moyekongling 2020-11-13
Ida 2020-09-16
liuweiq 2020-09-09
坚持是一种品质 2020-11-16
chenjiazhu 2020-09-29
kikaylee 2020-10-31
silencehgt 2020-09-07
sunnyxuebuhui 2020-09-07
西瓜皮儿的皮儿 2020-09-07
LuckyLXG 2020-09-08
明瞳 2020-08-19
MissFuTT 2020-08-18
jzlixiao 2020-08-18
zhushenghan 2020-08-16
罗罗 2020-08-16
mrandy 2020-08-15
houdaxiami 2020-08-15