mysql第五课
修改表中一行或多行数据:
SELECT*FROM student;
+----+------+------+
| 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
检查: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
删除数据:SELECT*FROM accout;
+----+------+-------+
| id | name | money |
+----+------+-------+
| 1 | a | 800 |
| 2 | b | 1200 |
+----+------+-------+
2 rows in set
DELETE FROM accout WHERE name="a";
Query OK, 1 row affected
SELECT*FROM accout;
+----+------+-------+
| 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 表名;
以上是 mysql第五课 的全部内容, 来源链接: utcz.com/z/531970.html